Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a7ef102

Browse filesBrowse 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 <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 9e7c662 commit a7ef102
Copy full SHA for a7ef102

File tree

Expand file treeCollapse file tree

2 files changed

+4
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+4
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/crypto/hash.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/hash.js
+2-1Lines 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);
Collapse file

‎test/parallel/test-crypto-hash.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-hash.js
+2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.