odbc: fix heap-use-after-free on the FOR UPDATE cursor path - #4
Merged
Conversation
exec_core aliases `sql` onto the heap buffer returned by seer_sql_make_updatable when an updatable cursor rewrites the SELECT (ROWIDTOCHAR(ROWID), optionally FOR UPDATE). It then freed that buffer immediately after seer_stmt_prepare copied the SQL - but `sql` still pointed at it, and seer_sql_count_params(sql) read the freed memory a few lines later. ASan aborts on the live SQL_CONCUR_LOCK path. Defer free(rewritten) until after the last read of `sql` (the count_params call), and free separately on the prepare-error return. No path reads `sql` after the free now. Verified under ASan against live 11g: FOR UPDATE (SQL_CONCUR_LOCK) passes with no use-after-free report (40 pass / 0 fail). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Bug
exec_core(src/odbc/exec.c) handles updatable cursors by rewriting the SELECT (appendingROWIDTOCHAR(ROWID), andFOR UPDATEforSQL_CONCUR_LOCK) into a fresh heap buffer, then aliasing the localsqlpointer onto it:seer_stmt_preparecopies the SQL, so freeing the buffer is fine in principle — butsqlstill points at it, andseer_sql_count_params(sql)reads the freed memory. AddressSanitizer aborts on the liveSQL_CONCUR_LOCKpath.Fix
Defer
free(rewritten)until after the last read ofsql(thecount_paramscall), covering both the data-at-exec and normal exit paths, and free separately on theseer_stmt_prepareerror return. No path readssqlafter the free.Verified
Built with AddressSanitizer (
detect_leaks=1:abort_on_error=1) and run against live Oracle 11g XE:FOR UPDATE (SQL_CONCUR_LOCK)— PASS, no use-after-free report🤖 Generated with Claude Code