Skip to content

[mysqlnd] Fix result set field metadata length buffer over-read - #289

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

[mysqlnd] Fix result set field metadata length buffer over-read#289
iliaal wants to merge 1 commit into
PHP-8.4from
fix/rset-field-len-overread-84

Conversation

@iliaal

@iliaal iliaal commented Aug 24, 2026

Copy link
Copy Markdown
Owner

php_mysqlnd_rset_field_read() trusted the length-encoded string sizes sent by the server: a hostile server can place a length marker at the end of a field metadata packet whose value exceeds the remaining payload, so p advances past header.size and the command buffer before the next dereference, and attacker-controlled lengths get attached to pointers outside the packet that later feed memcpy() into the field memory pool. Each metadata string is now bounded by bailing out once p leaves the payload and rejecting lengths larger than the remaining bytes, mirroring the hardening already applied to php_mysqlnd_ok_read() and the other packet readers by GHSA-h35g-vwh6-m678. An audit of sibling readers found no other users of the READ_RSET_FIELD macro, and the trailing default-value check never dereferences its length; a hostile-server phpt test fails on the unpatched build with a bogus protocol warning from the over-read and passes after the fix.

The rset_field metadata reader trusted each length-encoded string size:
a hostile server could send a length marker at the end of a field packet
whose value exceeds the remaining payload, advancing p past header.size
and past the command buffer before the next dereference, and recording
attacker-controlled lengths on pointers outside the packet that later
feed memcpy() into the field memory pool. Bound each metadata string by
bailing once p leaves the payload and rejecting lengths larger than the
remaining bytes, mirroring the hardening applied to php_mysqlnd_ok_read()
and the other packet readers by GHSA-h35g-vwh6-m678; an audit found no
other users of the READ_RSET_FIELD macro and the trailing default-value
check never dereferences its length.
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