[mysqlnd] Fix OK packet message length buffer over-read - #23497
Open
iliaal wants to merge 1 commit into
Open
Conversation
iliaal
requested review from
SakiTakamachi,
bukka and
kamil-tekiela
as code owners
August 29, 2026 12:02
kamil-tekiela
approved these changes
Aug 29, 2026
The OK packet message-length varint is read after the last bounds check, so a length-encoded integer at the end of a packet can advance p past header.size and even past the end of the 4096-byte command buffer. The old MIN(net_len, buf_len - (p - begin)) clamp then underflows and passes an unclamped attacker-controlled length to mnd_pestrndup(), reading heap memory beyond both the packet and its allocation. Reject a message length that extends past the payload, matching php_mysqlnd_auth_response_read() from GHSA-h35g-vwh6-m678; an audit found no further readers using the vulnerable buf_len clamp.
iliaal
force-pushed
the
fix/ok-packet-len-overread-84
branch
from
August 29, 2026 13:19
64845e5 to
187dce5
Compare
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.
php_mysqlnd_ok_read() reads the length-encoded message length after its last bounds check, so a hostile varint at the end of an OK packet filling the 4096-byte buffer pushes p past header.size and the buffer end, underflows the MIN(net_len, buf_len - (p - begin)) clamp, and mnd_pestrndup() copies attacker-controlled bytes beyond the allocation. Smaller packets left stale command-buffer content in the message. A message length that extends past the payload is now rejected, matching php_mysqlnd_auth_response_read() from GHSA-h35g-vwh6-m678.