Skip to content

Commit

Permalink
crypto: fix scrypt keylen validation
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Apr 24, 2021
1 parent 4f11b8b commit 13e5047
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/internal/crypto/scrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
const {
validateCallback,
validateInteger,
validateInt32,
validateUint32,
} = require('internal/validators');

Expand Down Expand Up @@ -90,7 +91,7 @@ function check(password, salt, keylen, options) {

password = getArrayBufferOrView(password, 'password');
salt = getArrayBufferOrView(salt, 'salt');
validateUint32(keylen, 'keylen');
validateInt32(keylen, 'keylen', 0);

let { N, r, p, maxmem } = defaults;
if (options && options !== defaults) {
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-crypto-scrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ const badargs = [
args: ['', '', -42],
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
},
{
args: ['', '', 2147485780],
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
},
];

for (const options of good) {
Expand Down

0 comments on commit 13e5047

Please sign in to comment.