Skip to content

Fix signed dbconvert() return stored into size_t in dblib lastInsertId#114

Open
iliaal wants to merge 1 commit into
PHP-8.4from
pdo_dblib-lastid-sign
Open

Fix signed dbconvert() return stored into size_t in dblib lastInsertId#114
iliaal wants to merge 1 commit into
PHP-8.4from
pdo_dblib-lastid-sign

Conversation

@iliaal

@iliaal iliaal commented Jun 21, 2026

Copy link
Copy Markdown
Owner

dblib_handle_last_id() stored the DBINT return of dbconvert() into a size_t len. dbconvert() returns -1 on conversion failure, which sign-extends to SIZE_MAX and is passed as the length to zend_string_init(), reading far past the 40-byte buffer and requesting a SIZE_MAX allocation. Hold the result in a DBINT and bail on a negative return, matching the failure-returns-NULL handling already used for dbresults()/dbnextrow()/dbdatlen() earlier in the function. Triggering needs a live SQL Server returning an unconvertible @@IDENTITY, so there is no portable red/green test; follow-up to the buffer-overflow fix in php#22348.

dblib_handle_last_id() stored the DBINT return of dbconvert() into a
size_t len. dbconvert() returns -1 on conversion failure, which
sign-extends to SIZE_MAX and is passed as the length to
zend_string_init(), reading far past the 40-byte buffer and requesting a
SIZE_MAX allocation. Hold the result in a DBINT and bail on a negative
return, matching the failure-returns-NULL handling already used for
dbresults()/dbnextrow()/dbdatlen() earlier in the function.
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