mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
sqlite: validate maxSize argument in createTagStore()
Signed-off-by: anshikakalpana <anshikajain196872@gmail.com> PR-URL: https://github.com/nodejs/node/pull/63792 Fixes: https://github.com/nodejs/node/issues/63791 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
cd84d55c81
commit
d6d2a71bee
2 files changed
+50
-3
No files matched your search
+16
-3
@@ -1068,10 +1068,23 @@ void DatabaseSync::CreateTagStore(const FunctionCallbackInfo<Value>& args) {
|
||||
return;
|
||||
}
|
||||
int capacity = 1000;
|
||||
if (args.Length() > 0 && args[0]->IsNumber()) {
|
||||
capacity = args[0].As<Number>()->Value();
|
||||
if (args.Length() > 0 && !args[0]->IsUndefined()) {
|
||||
if (!args[0]->IsNumber()) {
|
||||
THROW_ERR_INVALID_ARG_TYPE(
|
||||
env->isolate(),
|
||||
"The \"maxSize\" argument must be a positive integer.");
|
||||
return;
|
||||
}
|
||||
double val = args[0].As<Number>()->Value();
|
||||
if (std::floor(val) != val || val <= 0 ||
|
||||
val > std::numeric_limits<int>::max()) {
|
||||
THROW_ERR_OUT_OF_RANGE(
|
||||
env->isolate(),
|
||||
"The \"maxSize\" argument must be a positive integer.");
|
||||
return;
|
||||
}
|
||||
capacity = static_cast<int>(val);
|
||||
}
|
||||
|
||||
BaseObjectPtr<SQLTagStore> session =
|
||||
SQLTagStore::Create(env, BaseObjectWeakPtr<DatabaseSync>(db), capacity);
|
||||
if (!session) {
|
||||
|
||||
@@ -257,6 +257,40 @@ test('a finished iterator stays done and does not restart', () => {
|
||||
assert.strictEqual(iter.next().done, true);
|
||||
});
|
||||
|
||||
test('createTagStore throws on invalid maxSize', () => {
|
||||
const db = new DatabaseSync(':memory:');
|
||||
|
||||
assert.throws(() => db.createTagStore(0), {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
message: /maxSize/,
|
||||
});
|
||||
|
||||
assert.throws(() => db.createTagStore(-1), {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
message: /maxSize/,
|
||||
});
|
||||
|
||||
assert.throws(() => db.createTagStore(NaN), {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
message: /maxSize/,
|
||||
});
|
||||
|
||||
assert.throws(() => db.createTagStore(1.5), {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
message: /maxSize/,
|
||||
});
|
||||
|
||||
assert.throws(() => db.createTagStore('abc'), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: /maxSize/,
|
||||
});
|
||||
|
||||
assert.throws(() => db.createTagStore(Number.MAX_SAFE_INTEGER), {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
message: /maxSize/,
|
||||
});
|
||||
});
|
||||
|
||||
test('sql.db returns the associated DatabaseSync instance', () => {
|
||||
assert.strictEqual(sql.db, db);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user