From c9802862b7cd9b72cde7a248c73307e1d8cd4a32 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Mon, 12 Dec 2022 10:25:55 +0100 Subject: [PATCH] crypto: fix error when getRandomValues is called without arguments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/45854 Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca Reviewed-By: Yagiz Nizipli Reviewed-By: Minwoo Jung Reviewed-By: Tobias Nießen --- lib/internal/crypto/random.js | 3 +++ test/wpt/status/WebCryptoAPI.json | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js index fe76cf1a69ef43..da1ecb80c8941f 100644 --- a/lib/internal/crypto/random.js +++ b/lib/internal/crypto/random.js @@ -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, } @@ -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)) { diff --git a/test/wpt/status/WebCryptoAPI.json b/test/wpt/status/WebCryptoAPI.json index 7e61cb4b5a47d8..9eb8c8a5f31bc2 100644 --- a/test/wpt/status/WebCryptoAPI.json +++ b/test/wpt/status/WebCryptoAPI.json @@ -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",