Skip to content

pem: avoid a pointer cast in pem_parse_data_openssh() (tidy-up) - #2422

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:casttidy
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:casttidy

Conversation

@vszakats

Copy link
Copy Markdown
Member

Follow-up to a343024 #2361
Follow-up to 0309229 #248

Copilot AI review requested due to automatic review settings July 24, 2026 09:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR is a small tidy-up in the OpenSSH private key parsing path, adjusting local buffer typing to avoid a pointer-to-pointer cast when base64-decoding key material in pem_parse_data_openssh().

Changes:

  • Change the base64 decode output buffer variable from unsigned char * to char * to match ssh2_base64_decode()’s char ** API.
  • Assign the decoded buffer into the struct string_buf as unsigned char * for subsequent binary parsing without changing parsing behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vszakats vszakats closed this in a7d05f9 Jul 24, 2026
@vszakats
vszakats deleted the casttidy branch July 24, 2026 09:53
vszakats added a commit that referenced this pull request Jul 24, 2026
Also use it from `ssh2_match_string()` to reduce casts.

Apparently casting the return pointer of `ssh2_get_string()` buffer is
frowned upon, though existing practice and not completelely clear if UB
or not.

Current practice (with two exceptions, now reduced to one in WinCNG
code) is to declare the return buffer as `unsigned char *`, then cast
that result everywhere on use. It results in excessive casts. The
frowned-upon alternative to avoid this, is to declare as `char *` and
pass it to `ssh2_get_string()` as `(unsigned char **)&data`. This new
API avoid this, and allows to declare as `char *data`, retrieve it
without cast, and use it without casts too.

Ref: #2420
Ref: a7d05f9 #2422

Closes #2424
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants