[mysqlnd] Fix result set field metadata length buffer over-read - #289
Open
iliaal wants to merge 1 commit into
Open
[mysqlnd] Fix result set field metadata length buffer over-read#289iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
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.
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_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.