sqlite: reject statement-less SQL in SQLTagStore - #65157
Draft
TrevorBurnham wants to merge 1 commit into
Draft
Conversation
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>
Collaborator
|
Review requested:
|
Renegade334
reviewed
Aug 9, 2026
Comment on lines
+3651
to
+3657
| // sqlite3_prepare_v2() reports success without producing a statement when | ||
| // the input holds no SQL, such as a comment. Such a statement cannot be | ||
| // bound or executed, so reject it instead of caching it. | ||
| if (s == nullptr) { | ||
| THROW_ERR_INVALID_ARG_VALUE(env, "The SQL query contains no statement."); | ||
| return BaseObjectPtr<StatementSync>(); | ||
| } |
Member
There was a problem hiding this comment.
I think this is the right approach, but if we do this for the tag store then we should also perform this check for db.prepare() (ie. throw at the point of preparation rather than at the point of attempting to step the null query).
const stmt = db.prepare('-- :-/') // currently succeeds
stmt.get() // currently fails at this point with ERR_INVALID_STATE
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.SQLTagStore::PrepareStatement()only checked the return code, so it cached aStatementSyncwrapping a 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. This now throwsERR_INVALID_ARG_VALUEinstead, and the rejected statement is not cached.The
StatementSyncmethods already avoid the crash because theirIsFinalized()guard treats a null statement as finalized.Fixes: #65149