Fix GH-22666: pdo_odbc heap overflow on oversized output param#149
Closed
iliaal wants to merge 1 commit into
Closed
Fix GH-22666: pdo_odbc heap overflow on oversized output param#149iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
odbc_stmt_param_hook() sizes an output-param buffer from the declared maxlen but then copies the runtime value into it using the value's own length, and at fetch-back hands ZVAL_STRINGL the driver-reported length. Both trust a length that can exceed the buffer: the input copy overflows the heap (controlled write), and on a truncated OUTPUT value the driver reports the full length via the shared indicator, so the readback over-reads. Record the bound capacity in a new outbuflen field and clamp the copy and the readback to it. LOB output is rejected at bind, so those copy sites stay unreachable. Fixes phpGH-22666
Owner
Author
|
Submitted upstream as php#22674. |
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.
ext/pdo_odbc sizes an output-param buffer from the declared maxlen but copies the runtime value in by its own length (heap write overflow) and reads it back by the driver-reported length, which on a truncated OUTPUT value exceeds the buffer (01004 over-read). Records the bound capacity and clamps both the input copy and the read-back to it. Over-long values are bounded to maxlen, which is all the driver round-trips anyway since the buffer is bound at maxlen before the value is known. Reproduces with the SQLite3 ODBC driver; the test skips without it.