Skip to content

publickey: fix potential OOB read - #2204

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

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

Conversation

@vszakats

@vszakats vszakats commented Jul 4, 2026

Copy link
Copy Markdown
Member

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: #2203 (comment)
Follow-up to c02d9b7

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
@vszakats
vszakats requested a review from Copilot July 4, 2026 11:35
@vszakats
vszakats marked this pull request as draft July 4, 2026 11:37

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 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_len unless sufficient bytes remain.

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

Comment thread src/publickey.c
Comment on lines +431 to +432
if(s + 8 <=
session->pkeyInit_data + session->pkeyInit_data_len) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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
vszakats marked this pull request as ready for review July 4, 2026 11:47
@vszakats

vszakats commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

Merged via e3fba52.

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