sqlite: reject statement-less SQL in SQLTagStore - #65157
Open
TrevorBurnham wants to merge 2 commits into
Open
Conversation
Collaborator
|
Review requested:
|
Renegade334
reviewed
Aug 9, 2026
TrevorBurnham
added a commit
to TrevorBurnham/node
that referenced
this pull request
Aug 9, 2026
Apply the same check to DatabaseSync::Prepare() so that statement-less
SQL is rejected at preparation instead of on first use.
Previously db.prepare('-- comment') returned a StatementSync whose
statement_ was null. Every method on it threw "statement has been
finalized", which was misleading because nothing had been finalized, and
the object was still inserted into statements_. Since IsFinalized() is
true for a null statement, its destructor skipped UntrackStatement() and
left a dangling pointer in the set that a later close() would finalize.
Refs: nodejs#65157 (comment)
Signed-off-by: Trevor Burnham <trevorburnham@gmail.com>
TrevorBurnham
added a commit
to TrevorBurnham/node
that referenced
this pull request
Aug 9, 2026
Apply the same check to DatabaseSync::Prepare() so that statement-less
SQL is rejected at preparation instead of on first use. This matches
SQLite's own oo1 JavaScript API, which throws when the SQL contains no
statements rather than exposing the C API's null statement pointer.
Previously db.prepare('-- comment') returned a StatementSync whose
statement_ was null. Every method on it threw "statement has been
finalized", which was misleading because nothing had been finalized, and
the object was still inserted into statements_. Since IsFinalized() is
true for a null statement, its destructor skipped UntrackStatement() and
left a dangling pointer in the set that a later close() would finalize.
Refs: nodejs#65157 (comment)
Refs: https://sqlite.org/wasm/doc/trunk/api-oo1.md
Signed-off-by: Trevor Burnham <trevorburnham@gmail.com>
TrevorBurnham
force-pushed
the
sqlite/fix-tagstore-null-stmt
branch
from
August 9, 2026 15:55
af2725f to
3d2d495
Compare
Renegade334
reviewed
Aug 9, 2026
TrevorBurnham
added a commit
to TrevorBurnham/node
that referenced
this pull request
Aug 9, 2026
Apply the same check to DatabaseSync::Prepare() so that statement-less
SQL is rejected at preparation instead of on first use. This matches
SQLite's own oo1 JavaScript API, which throws when the SQL contains no
statements rather than exposing the C API's null statement pointer.
Previously db.prepare('-- comment') returned a StatementSync whose
statement_ was null. Every method on it threw "statement has been
finalized", which was misleading because nothing had been finalized, and
the object was still inserted into statements_. Since IsFinalized() is
true for a null statement, its destructor skipped UntrackStatement() and
left a dangling pointer in the set that a later close() would finalize.
Refs: nodejs#65157 (comment)
Refs: https://sqlite.org/wasm/doc/trunk/api-oo1.md
Signed-off-by: Trevor Burnham <trevorburnham@gmail.com>
TrevorBurnham
force-pushed
the
sqlite/fix-tagstore-null-stmt
branch
from
August 9, 2026 19:18
3d2d495 to
45be4bd
Compare
TrevorBurnham
marked this pull request as ready for review
August 9, 2026 23:47
trivikr
approved these changes
Aug 10, 2026
This comment was marked as resolved.
This comment was marked as resolved.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65157 +/- ##
==========================================
- Coverage 90.33% 90.33% -0.01%
==========================================
Files 760 760
Lines 248523 248529 +6
Branches 46906 46895 -11
==========================================
- Hits 224511 224509 -2
+ Misses 15451 15450 -1
- Partials 8561 8570 +9
🚀 New features to boost your workflow:
|
sqlite3_prepare_v2() returns SQLITE_OK without producing a statement when its input holds no SQL, such as a comment. PrepareStatement() only checked the return code, so it cached a StatementSync wrapping a null sqlite3_stmt. Executing it reached sqlite3_clear_bindings(), which only guards against a null statement under SQLITE_ENABLE_API_ARMOR, and segfaulted. Reject such input instead of caching it. The StatementSync methods already avoid the crash because their IsFinalized() guard treats a null statement as finalized. Fixes: nodejs#65149 Signed-off-by: Trevor Burnham <trevorburnham@gmail.com>
Apply the same check to DatabaseSync::Prepare() so that statement-less
SQL is rejected at preparation instead of on first use. This matches
SQLite's own oo1 JavaScript API, which throws when the SQL contains no
statements rather than exposing the C API's null statement pointer.
Previously db.prepare('-- comment') returned a StatementSync whose
statement_ was null. Every method on it threw "statement has been
finalized", which was misleading because nothing had been finalized, and
the object was still inserted into statements_. Since IsFinalized() is
true for a null statement, its destructor skipped UntrackStatement() and
left a dangling pointer in the set that a later close() would finalize.
Refs: nodejs#65157 (comment)
Refs: https://sqlite.org/wasm/doc/trunk/api-oo1.md
Signed-off-by: Trevor Burnham <trevorburnham@gmail.com>
TrevorBurnham
force-pushed
the
sqlite/fix-tagstore-null-stmt
branch
from
August 10, 2026 01:49
45be4bd to
d7ad352
Compare
trivikr
approved these changes
Aug 10, 2026
Collaborator
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.
sqlite3_prepare_v2()returnsSQLITE_OKwithout producing a statement when its input holds no SQL, such as a comment or an empty string. Neither caller checked for this.SQLTagStorecached aStatementSyncwrapping the nullsqlite3_stmt. Executing it reachedsqlite3_clear_bindings(), which only guards against a null statement underSQLITE_ENABLE_API_ARMOR, and segfaulted:All four query methods (
run,get,all,iterate) were affected.db.prepare()returned aStatementSyncwhosestatement_was null. Every method on it threwstatement has been finalized, which was misleading because nothing had been finalized. It was also still inserted intostatements_, and becauseIsFinalized()is true for a null statement, its destructor skippedUntrackStatement()and left a dangling pointer that a laterclose()would finalize.Both now throw
ERR_INVALID_ARG_VALUEat preparation. SQL that merely contains comments is unaffected.Fixes: #65149