Repository navigation
Conversation
Fix by applying the pattern used in subsequent checks. "The status-response parsing checks `session->pkeyInit_data_len < 8`, but `s` has already been advanced by `publickey_response_id()`. On a malformed packet where the total length is >= 8 but the remaining bytes from `s` are < 8, this will read past the end when decoding `status`/`descr_len` (and the later checks occur after those reads). Please validate the remaining bytes relative to `s` before calling `ssh2_ntohu32()`." Reported by Copilot Bug: libssh2#2203 (comment) Follow-up to c02d9b7
There was a problem hiding this comment.
Pull request overview
This PR addresses a potential out-of-bounds read in libssh2_publickey_init() status-response parsing by validating buffer bounds relative to the advanced parsing cursor (s) before decoding status and descr_len.
Changes:
- Adjust the initial STATUS response bounds check to be relative to
s(post-publickey_response_id()advancement). - Prevent decoding
status/descr_lenunless sufficient bytes remain.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+431
to
+432
| if(s + 8 <= | ||
| session->pkeyInit_data + session->pkeyInit_data_len) { |
Member
Author
There was a problem hiding this comment.
In a next commit maybe, because the same issue applies to all the checks, except for
one added just recently elsewhere in this source.
vszakats
marked this pull request as ready for review
July 4, 2026 11:47
Member
Author
|
Merged via e3fba52. |
This was referenced Jul 4, 2026
vszakats
added a commit
that referenced
this pull request
Jul 4, 2026
Bug: #2204 (comment) Bug: #2203 (comment) (and the rest below) Closes #2205
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.
Fix by applying the pattern used in subsequent checks.
"The status-response parsing checks
session->pkeyInit_data_len < 8,but
shas already been advanced bypublickey_response_id(). On amalformed packet where the total length is >= 8 but the remaining bytes
from
sare < 8, this will read past the end when decodingstatus/descr_len(and the later checks occur after those reads).Please validate the remaining bytes relative to
sbefore callingssh2_ntohu32()."Reported by Copilot
Bug: #2203 (comment)
Follow-up to c02d9b7