From c6436450ee1cccaf5c2e92605bf40714f4916c97 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 +++ 1 file changed, 3 insertions(+) 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)) {