Skip to content

publickey: cap packet size in publickey_packet_receive() - #2143

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

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

Conversation

@vszakats

Copy link
Copy Markdown
Member

Reported-by: manus-use on GitHub

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 hardens the publickey subsystem packet reader by validating the inbound packet length before allocating the response buffer, reducing the risk of excessive memory allocation from malformed/malicious responses.

Changes:

  • Add an upper-bound check for pkey->receive_packet_len in publickey_packet_receive() before allocation.
  • Return LIBSSH2_ERROR_OUT_OF_BOUNDARY when the publickey packet length exceeds LIBSSH2_PACKET_MAXPAYLOAD.

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

Comment thread src/publickey.c
Comment on lines 138 to +142
pkey->receive_packet_len = ssh2_ntohu32(buffer);
if(pkey->receive_packet_len > LIBSSH2_PACKET_MAXPAYLOAD) {
return ssh2_err(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY,
"Too large publickey packet");
}

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.

Pre-existing. A local check for this seems suboptimal, caller needs to free if it got data.

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.

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