Skip to content

publickey: fix potential OOB read in publickey_response_success() - #2147

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:pkeywrongbound
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:pkeywrongbound

Conversation

@vszakats

Copy link
Copy Markdown
Member

"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)

"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)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a potential out-of-bounds read in the publickey subsystem response parsing by correcting the length check to account for the variable-length response name consumed by publickey_response_id() before reading the 4-byte status value.

Changes:

  • Update publickey_response_success() to validate there are at least 4 bytes remaining at the advanced pointer s before calling ssh2_ntohu32(s).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vszakats vszakats closed this in ceaa7e1 Jun 30, 2026
@vszakats
vszakats deleted the pkeywrongbound branch June 30, 2026 09:33
vszakats added a commit to vszakats/libssh2 that referenced this pull request Jul 5, 2026
vszakats added a commit to vszakats/libssh2 that referenced this pull request Jul 17, 2026
vszakats added a commit that referenced this pull request Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants