Fix buffer overflow converting @@IDENTITY in pdo_dblib lastInsertId#22348
Closed
iliaal wants to merge 1 commit into
Closed
Fix buffer overflow converting @@IDENTITY in pdo_dblib lastInsertId#22348iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
dblib_handle_last_id() converted the @@IDENTITY value into a 32-byte buffer with dbconvert()'s destination length set to -1, which disables FreeTDS's destination bounds check. A numeric(p,0) IDENTITY column with precision over ~30 produces a textual form longer than 32 bytes, overflowing the buffer. Size the buffer for the widest @@IDENTITY (numeric(38,0): 38 digits, sign, NUL) and pass the real destination length so dbconvert() stays in bounds, mirroring the explicit-destlen fix already in pdo_dblib_stmt_stringify_col().
SakiTakamachi
approved these changes
Jun 16, 2026
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.
dblib_handle_last_id() converts @@IDENTITY into a 32-byte buffer with dbconvert()'s destination length set to -1, which disables FreeTDS's destination bounds check. A numeric(p,0) IDENTITY column with precision above 30 produces a textual form longer than 32 bytes (31 digits plus a sign plus the NUL), overflowing the buffer.
Size the buffer for the widest @@IDENTITY (numeric(38,0) = 38 digits + sign + NUL = 40 bytes) and pass the real destination length, mirroring the existing fix in pdo_dblib_stmt_stringify_col().