Skip to content

Commit 2105790

Browse files
committed
fix: check for non negative value
1 parent b9699de commit 2105790

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

addon/mongocrypt.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,11 @@ MongoCrypt::MongoCrypt(const CallbackInfo& info) : ObjectWrap(info) {
572572
}
573573

574574
if (options.Has("keyExpirationMS")) {
575-
mongocrypt_setopt_key_expiration(mongo_crypt(),
576-
options.Get("keyExpirationMS").ToNumber().Int64Value());
575+
int64_t keyExpirationMS = options.Get("keyExpirationMS").ToNumber().Int64Value();
576+
if (keyExpirationMS < 0) {
577+
throw TypeError::New(Env(), "Option `keyExpirationMS` must be a non-negative number");
578+
}
579+
mongocrypt_setopt_key_expiration(mongo_crypt(), keyExpirationMS);
577580
}
578581

579582
mongocrypt_setopt_use_range_v2(mongo_crypt());

test/unit/bindings.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('MongoCryptConstructor', () => {
110110
it('throws an error', () => {
111111
expect(() => {
112112
new MongoCrypt({ kmsProviders: serialize({ aws: {} }), keyExpirationMS: -1000000 });
113-
}).to.throw(TypeError);
113+
}).to.throw(/must be a non-negative number/);
114114
});
115115
});
116116
});

0 commit comments

Comments
 (0)