Skip to content

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

Closed
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:pdo_dblib-lastid-sign
Closed

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

Conversation

@iliaal

@iliaal iliaal commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

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 #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.

@SakiTakamachi SakiTakamachi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@iliaal iliaal closed this in c946819 Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants