Skip to content

Commit a7ef102

Browse files
cjihrigtargos
authored andcommitted
crypto: add null check to outputLength logic
The Hash constructor's outputLength logic checks if the options input is an object, but doesn't check for null objects. This commit adds that check. PR-URL: #28864 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 9e7c662 commit a7ef102

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/internal/crypto/hash.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ function Hash(algorithm, options) {
3636
if (!(this instanceof Hash))
3737
return new Hash(algorithm, options);
3838
validateString(algorithm, 'algorithm');
39-
const xofLen = typeof options === 'object' ? options.outputLength : undefined;
39+
const xofLen = typeof options === 'object' && options !== null ?
40+
options.outputLength : undefined;
4041
if (xofLen !== undefined)
4142
validateUint32(xofLen, 'options.outputLength');
4243
this[kHandle] = new _Hash(algorithm, xofLen);

test/parallel/test-crypto-hash.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ common.expectsError(
191191
// Default outputLengths.
192192
assert.strictEqual(crypto.createHash('shake128').digest('hex'),
193193
'7f9c2ba4e88f827d616045507605853e');
194+
assert.strictEqual(crypto.createHash('shake128', null).digest('hex'),
195+
'7f9c2ba4e88f827d616045507605853e');
194196
assert.strictEqual(crypto.createHash('shake256').digest('hex'),
195197
'46b9dd2b0ba88d13233b3feb743eeb24' +
196198
'3fcd52ea62b81b82b50c27646ed5762f');

0 commit comments

Comments
 (0)