Skip to content

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

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

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

Conversation

@iliaal

@iliaal iliaal commented Aug 24, 2026

Copy link
Copy Markdown
Owner

php_mysqlnd_ok_read() reads the length-encoded message length after its last bounds check, so a malicious server can place the varint at the very end of an OK packet that fills the 4096-byte command buffer. The varint read then advances p past header.size and past the end of the command buffer, the old MIN(net_len, buf_len - (p - begin)) clamp underflows to a huge value, and mnd_pestrndup() copies an unclamped attacker-controlled number of bytes from beyond the allocation; with smaller packets the message is filled with stale command-buffer content, which the new fake-server test demonstrates as mysqli_info() returning leftover greeting bytes. The fix bails out via BAIL_IF_NO_MORE_DATA once p moves past the payload and clamps against header.size instead of buf_len, mirroring the hardening GHSA-h35g-vwh6-m678 already applied to the auth response and result-set readers; an audit found no other readers still using the vulnerable buf_len clamp.

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; even in the non-
overflowing case the message was filled with stale command-buffer bytes.
Bail out via BAIL_IF_NO_MORE_DATA once the varint advances p past the
payload and clamp against header.size instead of buf_len, matching the
hardening already applied to php_mysqlnd_auth_response_read() and the
other packet readers by GHSA-h35g-vwh6-m678; an audit found no further
readers using the vulnerable buf_len clamp.
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.

1 participant