Skip to content

Commit c1d9b5b

Browse files
aduh95targos
authored andcommitted
crypto: fix scrypt keylen validation
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]>
1 parent 28f02cb commit c1d9b5b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/internal/crypto/scrypt.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const {
1616
const {
1717
validateCallback,
1818
validateInteger,
19+
validateInt32,
1920
validateUint32,
2021
} = require('internal/validators');
2122

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

9192
password = getArrayBufferOrView(password, 'password');
9293
salt = getArrayBufferOrView(salt, 'salt');
93-
validateUint32(keylen, 'keylen');
94+
validateInt32(keylen, 'keylen', 0);
9495

9596
let { N, r, p, maxmem } = defaults;
9697
if (options && options !== defaults) {

test/parallel/test-crypto-scrypt.js

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ const badargs = [
143143
args: ['', '', -42],
144144
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
145145
},
146+
{
147+
args: ['', '', 2147485780],
148+
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
149+
},
146150
];
147151

148152
for (const options of good) {

0 commit comments

Comments
 (0)