Skip to content

userauth: apply two OOB fixes to userauth_read_blob_pubkey() - #2358

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:ua-pubkey-fix
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:ua-pubkey-fix

Conversation

@vszakats

@vszakats vszakats commented Jul 19, 2026 •

Copy link
Copy Markdown
Member
  • fix off by one error when loading public keys with no id.
  • make sure that sp_len is positive and avoid overflows.

These were fixed in userauth_read_file_pubkey() earlier, but missed
from the sibling code loading pubkey from memory buffer (as opposed to
file). Sibling code made it into the codebase after the first fix, but
it was based code copy-pasted from a pre-fix revision.

Bug: #2354 (comment)
Follow-up to 4820556 #386
Follow-up to 18cfec8
Follow-up to 3e47ca8

- fix off by one error when loading public keys with no id.
- make sure that sp_len is positive and avoid overflows.

These were fixed in `userauth_read_file_pubkey()` earlier, but missed
from the same code loading pubkeys from memory buffers.

Follow-up to 4820556 libssh2#386
Follow-up to 3e47ca8
@vszakats vszakats changed the title userauth: apply pubkey OOB fixes to userauth_read_blob_pubkey() userauth: apply two OOB fixes to userauth_read_blob_pubkey() Jul 19, 2026
@vszakats
vszakats requested a review from Copilot July 19, 2026 12:38

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 brings the in-memory public key parsing path (userauth_read_blob_pubkey()) in line with the previously-fixed file-based path (userauth_read_file_pubkey()), addressing an out-of-bounds/underflow risk when searching for the optional id/comment field and tightening length arithmetic to avoid overflow/underflow cases.

Changes:

  • Compute a bounded sp_len before subtracting from pubkey_len to avoid potential unsigned underflow in the memchr() scan length.
  • Align local variable declarations between the blob and file pubkey parsing functions for consistency.

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

@vszakats vszakats closed this in 209522c Jul 19, 2026
@vszakats
vszakats deleted the ua-pubkey-fix branch July 19, 2026 12:50
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