diff options
author | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2021-03-19 14:06:50 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2021-05-01 13:25:28 +0300 |
commit | 46ece20fe386ddf0d0d47e12b6f699483ec5a95c (patch) | |
tree | e9507a9195dd5f9dc028554a5791d4bb03f4218f /lib | |
parent | d89d55ab365c9bc92e6176d0ab4cacbe6d3dfb2b (diff) |
crypto: fix DiffieHellman argument validation
Fixes: https://github.com/nodejs/node/issues/37808
PR-URL: https://github.com/nodejs/node/pull/37810
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/crypto/diffiehellman.js | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/internal/crypto/diffiehellman.js b/lib/internal/crypto/diffiehellman.js index 8f86911757f..752aabb04c9 100644 --- a/lib/internal/crypto/diffiehellman.js +++ b/lib/internal/crypto/diffiehellman.js @@ -75,12 +75,20 @@ function DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) { if (typeof sizeOrKey !== 'number') sizeOrKey = toBuf(sizeOrKey, keyEncoding); - if (!generator) + if (!generator) { generator = DH_GENERATOR; - else if (typeof generator === 'number') + } else if (typeof generator === 'number') { validateInt32(generator, 'generator'); - else + } else if (generator !== true) { generator = toBuf(generator, genEncoding); + } else { + throw new ERR_INVALID_ARG_TYPE( + 'generator', + ['number', 'string', 'ArrayBuffer', 'Buffer', 'TypedArray', 'DataView'], + generator + ); + } + this[kHandle] = new _DiffieHellman(sizeOrKey, generator); ObjectDefineProperty(this, 'verifyError', { |