Repository navigation
Conversation
publickey_response_success() received <3 bytespublickey_response_success() received <8 bytes
There was a problem hiding this comment.
Pull request overview
This PR tightens error-path cleanup in the publickey subsystem by freeing the received response buffer when the response is shorter than expected, preventing leaks on malformed/truncated packets.
Changes:
- Free
databefore returning ondata_len < 4inpublickey_response_success(). - Free
databefore returning ondata_len < 8in the STATUS response path inpublickey_response_success().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+239
to
+243
| if(data_len < 8) { | ||
| SSH2_FREE(session, data); | ||
| return ssh2_err(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, | ||
| "Publickey response too small"); | ||
| } |
vszakats
added a commit
to vszakats/libssh2
that referenced
this pull request
Jun 30, 2026
"The size check for reading the 4-byte status field is incorrect: `data_len < 8` doesn't account for the variable-length response name that `publickey_response_id()` advances `s` past. A truncated packet like `[len=6]["status"]` (10 bytes total) will pass the current check but still cause an out-of-bounds read in `ssh2_ntohu32(s)`. The check should ensure there are at least 4 bytes remaining at `s`." Bug: libssh2#2144 (comment)
vszakats
added a commit
that referenced
this pull request
Jun 30, 2026
"The size check for reading the 4-byte status field is incorrect: `data_len < 8` doesn't account for the variable-length response name that `publickey_response_id()` advances `s` past. A truncated packet like `[len=6]["status"]` (10 bytes total) will pass the current check but still cause an out-of-bounds read in `ssh2_ntohu32(s)`. The check should ensure there are at least 4 bytes remaining at `s`." Reported by Copilot Bug: #2144 (comment) Closes #2147
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.
Ref: #2143 (comment)