Skip to content

Commit 139a8eb

Browse files
RaisinTenjuanarbol
authored andcommitted
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: #42492 Refs: #39941 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 81ef4cc commit 139a8eb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/crypto/crypto_dh.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ using v8::ReadOnly;
3030
using v8::SideEffectType;
3131
using v8::Signature;
3232
using v8::String;
33-
using v8::Uint8Array;
3433
using v8::Value;
3534

3635
namespace crypto {
@@ -631,8 +630,10 @@ void DiffieHellman::Stateless(const FunctionCallbackInfo<Value>& args) {
631630
ManagedEVPPKey our_key = our_key_object->Data()->GetAsymmetricKey();
632631
ManagedEVPPKey their_key = their_key_object->Data()->GetAsymmetricKey();
633632

634-
Local<Value> out = StatelessDiffieHellmanThreadsafe(our_key, their_key)
635-
.ToBuffer(env).FromMaybe(Local<Uint8Array>());
633+
Local<Value> out;
634+
if (!StatelessDiffieHellmanThreadsafe(our_key, their_key)
635+
.ToBuffer(env)
636+
.ToLocal(&out)) return;
636637

637638
if (Buffer::Length(out) == 0)
638639
return ThrowCryptoError(env, ERR_get_error(), "diffieHellman failed");

0 commit comments

Comments
 (0)