Fix pdo_odbc output-buffer leak and stale-binding out-of-bounds read#22735
Open
iliaal wants to merge 1 commit into
Open
Fix pdo_odbc output-buffer leak and stale-binding out-of-bounds read#22735iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
SQLBindParameter recorded deferred pointers (P->outbuf, &P->len, and the bound-parameter struct) into the ODBC statement at PDO_PARAM_EVT_ALLOC, and P->outbuf was never freed. Both outlive the bound-parameter struct, which PDO destroys mid-statement on execute() with an array or a rebind: the buffer leaked and the stale binding made the next SQLExecute read freed memory. Track output buffers on the statement and free them in the destructor, and defer binding to execute time, resetting and rebinding the current parameters when the set changed. Closes phpGH-22735
fa0df82 to
5406151
Compare
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.
pdo_odbc bound each parameter with
SQLBindParameteratPDO_PARAM_EVT_ALLOC, recording deferred pointers (P->outbuffor output,&P->len, and the bound-parameter struct itself for input) into the ODBC statement, and never freedP->outbuf. Both outlive the bound-parameter struct, which PDO destroys mid-statement whenexecute()is given an array or a position is rebound, so the output buffer leaked and the stale binding made the nextSQLExecuteread freed memory. This tracks the output buffers on the statement and frees them in the destructor afterSQLFreeHandle, and defersSQLBindParameterto execute time, rebinding the current parameters when the parameter set has changed.Reproducers, both under a debug or ASAN build: