Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarshan Sen <raisinten@gmail.com>2022-03-27 15:50:20 +0300
committerNode.js GitHub Bot <github-bot@iojs.org>2022-03-31 07:29:55 +0300
commitf2a22ef17906f3c2698dd56e9e97cee061001070 (patch)
treead6ae22825c47d409427dfcb8d9ccb3f9b4e574f /src/crypto
parent11c0da67f9c013f0132b2036f584793a5a36ad80 (diff)
src,crypto: handle empty maybe correctly in crypto_dh.cc
Buffer::Length() dereferences the passed Local, so calling it when the underlying pointer is a nullptr would lead to a crash. This fixes that by returning early instead. Signed-off-by: Darshan Sen <raisinten@gmail.com> PR-URL: https://github.com/nodejs/node/pull/42492 Refs: https://github.com/nodejs/node/pull/39941 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/crypto_dh.cc7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/crypto/crypto_dh.cc b/src/crypto/crypto_dh.cc
index 83f101e39b9..702c5e083f8 100644
--- a/src/crypto/crypto_dh.cc
+++ b/src/crypto/crypto_dh.cc
@@ -32,7 +32,6 @@ using v8::ReadOnly;
using v8::SideEffectType;
using v8::Signature;
using v8::String;
-using v8::Uint8Array;
using v8::Value;
namespace crypto {
@@ -637,8 +636,10 @@ void DiffieHellman::Stateless(const FunctionCallbackInfo<Value>& args) {
ManagedEVPPKey our_key = our_key_object->Data()->GetAsymmetricKey();
ManagedEVPPKey their_key = their_key_object->Data()->GetAsymmetricKey();
- Local<Value> out = StatelessDiffieHellmanThreadsafe(our_key, their_key)
- .ToBuffer(env).FromMaybe(Local<Uint8Array>());
+ Local<Value> out;
+ if (!StatelessDiffieHellmanThreadsafe(our_key, their_key)
+ .ToBuffer(env)
+ .ToLocal(&out)) return;
if (Buffer::Length(out) == 0)
return ThrowCryptoError(env, ERR_get_error(), "diffieHellman failed");