sqlite: validate aggregate() name and options

`Database.prototype.aggregate()` cast its arguments without checking
their types, so a missing `options` leaked a raw V8 TypeError and a
non-string `name` was silently coerced. Throw `ERR_INVALID_ARG_TYPE`
like the other sqlite bindings do.

Assisted-by: Claude Code
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66463
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
Guilherme Araújo authored and Antoine du Hamel committed 2026-11-11 17:28:05 +01:00
1 parent 442228edeb
commit 4e9f656566
2 files changed
+31

No files matched your search

+13
View File
@@ -2040,6 +2040,19 @@ void DatabaseSync::AggregateFunction(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
THROW_AND_RETURN_ON_BAD_STATE(env, !db->IsOpen(), "database is not open");
THROW_AND_RETURN_IF_IN_AUTHORIZER(env, db);
if (!args[0]->IsString()) {
THROW_ERR_INVALID_ARG_TYPE(env->isolate(),
"The \"name\" argument must be a string.");
return;
}
if (!args[1]->IsObject()) {
THROW_ERR_INVALID_ARG_TYPE(env->isolate(),
"The \"options\" argument must be an object.");
return;
}
Utf8Value name(env->isolate(), args[0].As<String>());
Local<Object> options = args[1].As<Object>();
Local<Value> start_v;
@@ -7,6 +7,24 @@ describe('DatabaseSync.prototype.aggregate()', () => {
describe('input validation', () => {
const db = new DatabaseSync(':memory:');
test('throws if name is not a string', (t) => {
t.assert.throws(() => {
db.aggregate(123, { start: 0, step: () => {} });
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "name" argument must be a string.'
});
});
test('throws if options is not an object', (t) => {
t.assert.throws(() => {
db.aggregate('sum');
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be an object.'
});
});
test('throws if options.start is not provided', (t) => {
t.assert.throws(() => {
db.aggregate('sum', {