From 899de04a267db5c85080c195056b93f021ddad7d Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sun, 27 Mar 2022 18:20:20 +0530 Subject: [PATCH] src,crypto: handle empty maybe correctly in crypto_dh.cc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 PR-URL: https://github.com/nodejs/node/pull/42492 Refs: https://github.com/nodejs/node/pull/39941 Reviewed-By: Tobias Nießen Reviewed-By: Anna Henningsen --- src/crypto/crypto_dh.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/crypto/crypto_dh.cc b/src/crypto/crypto_dh.cc index 83f101e39b96a6..702c5e083f8f80 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& args) { ManagedEVPPKey our_key = our_key_object->Data()->GetAsymmetricKey(); ManagedEVPPKey their_key = their_key_object->Data()->GetAsymmetricKey(); - Local out = StatelessDiffieHellmanThreadsafe(our_key, their_key) - .ToBuffer(env).FromMaybe(Local()); + Local 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");