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: https://github.com/nodejs/node/pull/28864
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
cjihrig 2019-07-26 10:32:40 -04:00
parent 62a809fa54
commit 92ca2c208b
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
2 changed files with 4 additions and 1 deletions

View File

@ -36,7 +36,8 @@ function Hash(algorithm, options) {
if (!(this instanceof Hash))
return new Hash(algorithm, options);
validateString(algorithm, 'algorithm');
const xofLen = typeof options === 'object' ? options.outputLength : undefined;
const xofLen = typeof options === 'object' && options !== null ?
options.outputLength : undefined;
if (xofLen !== undefined)
validateUint32(xofLen, 'options.outputLength');
this[kHandle] = new _Hash(algorithm, xofLen);

View File

@ -191,6 +191,8 @@ common.expectsError(
// Default outputLengths.
assert.strictEqual(crypto.createHash('shake128').digest('hex'),
'7f9c2ba4e88f827d616045507605853e');
assert.strictEqual(crypto.createHash('shake128', null).digest('hex'),
'7f9c2ba4e88f827d616045507605853e');
assert.strictEqual(crypto.createHash('shake256').digest('hex'),
'46b9dd2b0ba88d13233b3feb743eeb24' +
'3fcd52ea62b81b82b50c27646ed5762f');