Skip to content

Fix GH-22666: pdo_odbc heap overflow on oversized output param#149

Closed
iliaal wants to merge 1 commit into
PHP-8.4from
fix/gh-22666-pdo-odbc-param-overflow
Closed

Fix GH-22666: pdo_odbc heap overflow on oversized output param#149
iliaal wants to merge 1 commit into
PHP-8.4from
fix/gh-22666-pdo-odbc-param-overflow

Conversation

@iliaal

@iliaal iliaal commented Jul 10, 2026

Copy link
Copy Markdown
Owner

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.

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
@iliaal

iliaal commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#22674.

@iliaal iliaal closed this Jul 10, 2026
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