Skip to content

Commit

Permalink
crypto: turn impossible DH errors into assertions
Browse files Browse the repository at this point in the history
PR-URL: #31934
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
tniessen authored and codebytere committed Mar 30, 2020
1 parent 54395c6 commit f9113fd
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5884,11 +5884,7 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) {

ClearErrorOnReturn clear_error_on_return;

if (args.Length() == 0) {
return THROW_ERR_MISSING_ARGS(
env, "Other party's public key argument is mandatory");
}

CHECK_EQ(args.Length(), 1);
THROW_AND_RETURN_IF_NOT_BUFFER(env, args[0], "Other party's public key");
ArrayBufferViewContents<unsigned char> key_buf(args[0].As<ArrayBufferView>());
BignumPointer key(BN_bin2bn(key_buf.data(), key_buf.length(), nullptr));
Expand Down Expand Up @@ -5948,11 +5944,7 @@ void DiffieHellman::SetKey(const FunctionCallbackInfo<Value>& args,

char errmsg[64];

if (args.Length() == 0) {
snprintf(errmsg, sizeof(errmsg), "%s argument is mandatory", what);
return THROW_ERR_MISSING_ARGS(env, errmsg);
}

CHECK_EQ(args.Length(), 1);
if (!Buffer::HasInstance(args[0])) {
snprintf(errmsg, sizeof(errmsg), "%s must be a buffer", what);
return THROW_ERR_INVALID_ARG_TYPE(env, errmsg);
Expand Down

0 comments on commit f9113fd

Please sign in to comment.