Skip to content

[mysqlnd] Fix OK packet message length buffer over-read - #23497

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/ok-packet-len-overread-84
Open

[mysqlnd] Fix OK packet message length buffer over-read#23497
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/ok-packet-len-overread-84

Conversation

@iliaal

@iliaal iliaal commented Aug 29, 2026

Copy link
Copy Markdown
Member

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.

Comment thread ext/mysqli/tests/mysqlnd_ok_packet_message_over_read.phpt Outdated
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
iliaal force-pushed the fix/ok-packet-len-overread-84 branch from 64845e5 to 187dce5 Compare August 29, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants