Repository navigation
Conversation
Also use it from `ssh2_match_string()` to reduce casts. Apparently casting the return pointer of `ssh2_get_string()` string is frowned upon, though existing practice and not completelely clear if UB or not. Ref: libssh2#2420
There was a problem hiding this comment.
Pull request overview
This PR introduces a char **-returning variant of ssh2_get_string() to centralize the cast from the underlying unsigned char * buffer, and updates ssh2_match_string() to use the new helper to reduce call-site casting during SSH packet parsing.
Changes:
- Add
ssh2_get_schars()declaration to the internal misc header. - Implement
ssh2_get_schars()insrc/misc.c. - Switch
ssh2_match_string()to usessh2_get_schars()and remove the call-site cast.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/misc.h | Declares the new ssh2_get_schars() helper. |
| src/misc.c | Implements ssh2_get_schars() and uses it in ssh2_match_string(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+899
to
903
| char *out; | ||
| size_t len = 0; | ||
| if(ssh2_get_string(buf, &out, &len) || len != strlen(match) || | ||
| strncmp((const char *)out, match, strlen(match))) | ||
| if(ssh2_get_schars(buf, &out, &len) || len != strlen(match) || | ||
| strncmp(out, match, strlen(match))) | ||
| return -1; |
Member
Author
There was a problem hiding this comment.
Yeah, future PR. Though with 4 callers in non-hot path, this is picky of the picky, but why not.
ssh2_get_string()ssh2_get_string()
This was referenced Jul 24, 2026
vszakats
added a commit
that referenced
this pull request
Jul 24, 2026
vszakats
added a commit
that referenced
this pull request
Jul 24, 2026
vszakats
added a commit
that referenced
this pull request
Jul 24, 2026
- change types to match common usage to reduce casts. (mostly `unsigned char *` to `char *`) - use non-unsigned variant of `ssh2_get_string()`. - use `void *` arg in `kex_value_hash()` to avoid casts. - packet: replace magic number with `sizeof()` in `ssh2_packet_add()`, also make the constant static. - drop redundant casts missed earlier. Follow-up to 907fe84 #2424 Closes #2420
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Also use it from
ssh2_match_string()to reduce casts.Apparently casting the return pointer of
ssh2_get_string()buffer isfrowned 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 castthat result everywhere on use. It results in excessive casts. The
frowned-upon alternative to avoid this, is to declare as
char *andpass it to
ssh2_get_string()as(unsigned char **)&data. This newAPI avoid this, and allows to declare as
char *data, retrieve itwithout cast, and use it without casts too.
Ref: #2420
Ref: a7d05f9 #2422