sqlite: check database state before calling SQLite · nodejs/node@6abd00e · GitHub
Skip to content

Commit 6abd00e

Browse files
trivikraduh95
authored andcommitted
sqlite: check database state before calling SQLite
Check whether the database is open in enableLoadExtension() and setAuthorizer() before passing the connection to SQLite. This prevents calls after close() from terminating the process and makes them throw ERR_INVALID_STATE instead. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: codex:gpt-5.6-sol PR-URL: #64812 Fixes: #64811 Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com> Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
1 parent 9016dda commit 6abd00e

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/node_sqlite.cc

Lines changed: 7 additions & 2 deletions

test/parallel/test-sqlite-authz.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,16 @@ suite('DatabaseSync.prototype.setAuthorizer()', () => {
275275
message: /The "callback" argument must be a function/
276276
});
277277
});
278+
279+
it('throws if database is not open', () => {
280+
const db = new DatabaseSync(':memory:');
281+
db.close();
282+
283+
assert.throws(() => {
284+
db.setAuthorizer(() => constants.SQLITE_OK);
285+
}, {
286+
code: 'ERR_INVALID_STATE',
287+
message: 'database is not open',
288+
});
289+
});
278290
});

test/parallel/test-sqlite-config.js

Lines changed: 12 additions & 0 deletions

0 commit comments

Comments
 (0)