Skip to content

Commit

Permalink
crypto: fix scrypt keylen validation
Browse files Browse the repository at this point in the history
Fixes: #38381

PR-URL: #38385
Reviewed-By: Nitzan Uziely <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Zijian Liu <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
  • Loading branch information
aduh95 authored and targos committed Apr 29, 2021
1 parent 28f02cb commit c1d9b5b
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 c1d9b5b

Please sign in to comment.