Skip to content

Commit 7845769

Browse files
RaisinTenxtx1130
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 <[email protected]> PR-URL: nodejs#42492 Refs: nodejs#39941 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent b59678a commit 7845769

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
@@ -32,7 +32,6 @@ using v8::ReadOnly;
3232
using v8::SideEffectType;
3333
using v8::Signature;
3434
using v8::String;
35-
using v8::Uint8Array;
3635
using v8::Value;
3736

3837
namespace crypto {
@@ -637,8 +636,10 @@ void DiffieHellman::Stateless(const FunctionCallbackInfo<Value>& args) {
637636
ManagedEVPPKey our_key = our_key_object->Data()->GetAsymmetricKey();
638637
ManagedEVPPKey their_key = their_key_object->Data()->GetAsymmetricKey();
639638

640-
Local<Value> out = StatelessDiffieHellmanThreadsafe(our_key, their_key)
641-
.ToBuffer(env).FromMaybe(Local<Uint8Array>());
639+
Local<Value> out;
640+
if (!StatelessDiffieHellmanThreadsafe(our_key, their_key)
641+
.ToBuffer(env)
642+
.ToLocal(&out)) return;
642643

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

0 commit comments

Comments
 (0)