Skip to content

Commit

Permalink
crypto: fix error when getRandomValues is called without arguments
Browse files Browse the repository at this point in the history
PR-URL: #45854
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
panva committed Dec 16, 2022
1 parent 3dbd686 commit 3014c5d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/internal/crypto/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const { Buffer, kMaxLength } = require('buffer');
const {
codes: {
ERR_INVALID_ARG_TYPE,
ERR_MISSING_ARGS,
ERR_OUT_OF_RANGE,
ERR_OPERATION_FAILED,
}
Expand Down Expand Up @@ -315,6 +316,8 @@ function onJobDone(buf, callback, error) {
// not allowed to exceed 65536 bytes, and can only
// be an integer-type TypedArray.
function getRandomValues(data) {
if (arguments.length < 1)
throw new ERR_MISSING_ARGS('typedArray');
if (!isTypedArray(data) ||
isFloat32Array(data) ||
isFloat64Array(data)) {
Expand Down
1 change: 0 additions & 1 deletion test/wpt/status/WebCryptoAPI.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"fail": {
"expected": [
"Crypto interface: existence and properties of interface object",
"Crypto interface: calling getRandomValues(ArrayBufferView) on crypto with too few arguments must throw TypeError",
"CryptoKey interface: existence and properties of interface object",
"CryptoKey interface: existence and properties of interface prototype object",
"CryptoKey interface: attribute type",
Expand Down

0 comments on commit 3014c5d

Please sign in to comment.