Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
Reworks bounds checking in src/publickey.c when parsing publickey subsystem responses, aiming to prevent out-of-bounds reads by validating packet offsets relative to the current parse cursor rather than relying on pointer-end comparisons.
Changes:
- Replaces pointer-comparison bounds checks with
data_lenvs(cursor - base)style checks in publickey init response parsing. - Applies the same offset-based bounds-check pattern across the
libssh2_publickey_list_fetch()response parsing paths (status, v1, v2, and attrs parsing).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+442
to
+443
| if(session->pkeyInit_data_len < | ||
| (size_t)(s - session->pkeyInit_data) + descr_len + 4) { |
Member
Author
There was a problem hiding this comment.
Fixing in a future commit by capping individual variable-length packet elements to sane values.
FTR the max length for a whole packet is 40KB, via LIBSSH2_PACKET_MAXPAYLOAD.
Comment on lines
+453
to
+454
| if(session->pkeyInit_data_len < | ||
| (size_t)(s - session->pkeyInit_data) + lang_len) { |
Comment on lines
+851
to
854
| if(pkey->listFetch_data_len < | ||
| (size_t)(pkey->listFetch_s - pkey->listFetch_data) + | ||
| descr_len + 4) { | ||
| ssh2_err(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, |
Comment on lines
+863
to
+864
| if(pkey->listFetch_data_len < | ||
| (size_t)(pkey->listFetch_s - pkey->listFetch_data) + lang_len) { |
Comment on lines
+921
to
+923
| if(pkey->listFetch_data_len < | ||
| (size_t)(pkey->listFetch_s - pkey->listFetch_data) + | ||
| comment_len) { |
Comment on lines
+980
to
+982
| if(pkey->listFetch_data_len < | ||
| (size_t)(pkey->listFetch_s - pkey->listFetch_data) + | ||
| list[keys].blob_len) { |
Comment on lines
+1002
to
+1004
| if(pkey->listFetch_data_len < | ||
| (size_t)(pkey->listFetch_s - pkey->listFetch_data) + | ||
| list[keys].name_len) { |
Comment on lines
+1021
to
+1023
| if(pkey->listFetch_data_len < | ||
| (size_t)(pkey->listFetch_s - pkey->listFetch_data) + | ||
| list[keys].blob_len) { |
Comment on lines
+1068
to
+1070
| if(pkey->listFetch_data_len < | ||
| (size_t)(pkey->listFetch_s - pkey->listFetch_data) + | ||
| list[keys].attrs[i].name_len) { |
Comment on lines
+1089
to
+1091
| if(pkey->listFetch_data_len < | ||
| (size_t)(pkey->listFetch_s - pkey->listFetch_data) + | ||
| list[keys].attrs[i].value_len) { |
vszakats
marked this pull request as draft
July 4, 2026 14:47
vszakats
marked this pull request as ready for review
July 4, 2026 15:01
vszakats
added a commit
that referenced
this pull request
Jul 5, 2026
To avoid potential offset wrap in 32-bit builds when receiving overly large values in length fields. Limit them to the maximum packet size. Bug: #2205 (comment) Closes #2207
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.
#2204 (comment)
#2203 (comment) (and the rest below)