crypto: fix scrypt keylen validation

Fixes: https://github.com/nodejs/node/issues/38381

PR-URL: https://github.com/nodejs/node/pull/38385
Reviewed-By: Nitzan Uziely <linkgoron@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
Antoine du Hamel 2021-04-24 18:02:05 +02:00 committed by James M Snell
parent 59db84aba1
commit 27beb386a8
No known key found for this signature in database
GPG Key ID: 7341B15C070877AC
2 changed files with 6 additions and 1 deletions

View File

@ -16,6 +16,7 @@ const {
const {
validateCallback,
validateInteger,
validateInt32,
validateUint32,
} = require('internal/validators');
@ -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) {

View File

@ -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) {