Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens parsing of publickey subsystem packets in publickey_init() to prevent potential heap out-of-bounds reads when handling truncated or malformed responses (follow-up to earlier response-length validation fixes).
Changes:
- Update length checks to account for how
publickey_response_id()advances the parsing pointers(i.e., validate remaining bytes ats, not just total packet length). - Tighten bounds validation for STATUS response parsing before reading fixed-width fields.
- Add an explicit bounds check before reading the VERSION response’s 4-byte version field.
Comments suppressed due to low confidence (1)
src/publickey.c:425
- The new pre-switch length check applies to all response types, including ones that are intentionally ignored in the
default:branch (and potentiallySSH2_PUBLICKEY_RESPONSE_PUBLICKEY). This changes behavior: a packet containing only the response name (no trailing fields) would previously be ignored for unknown responses, but will now abort with BUFFER_TOO_SMALL before reaching thedefault:handler. Since each handled case already performs its own length validation, limit this check to the response types that actually require a 4-byte field here (STATUS/VERSION), or remove it entirely and rely on the per-case checks.
if(session->pkeyInit_data_len <
(size_t)(s - session->pkeyInit_data) + 4) {
ssh2_err(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
"Public key init data too small");
goto err_exit;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Reported-by: Haruki Oyama Follow-up to ceaa7e1 libssh2#2147
Member
Author
|
Also reported by Mateusz Gierblinski. |
vszakats
added a commit
that referenced
this pull request
Jul 22, 2026
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.
Reported-by: Mateusz Gierblinski
Reported-by: Haruki Oyama
Follow-up to ceaa7e1 #2147