Skip to content

Commit

Permalink
src,crypto: handle empty maybe correctly in crypto_dh.cc
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
RaisinTen authored and juanarbol committed May 31, 2022
1 parent 81ef4cc commit 139a8eb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/crypto/crypto_dh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ using v8::ReadOnly;
using v8::SideEffectType;
using v8::Signature;
using v8::String;
using v8::Uint8Array;
using v8::Value;

namespace crypto {
Expand Down Expand Up @@ -631,8 +630,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");
Expand Down

0 comments on commit 139a8eb

Please sign in to comment.