Skip to content

Commit 46b92c8

Browse files
tniessenTrott
authored andcommitted
crypto: turn impossible DH errors into assertions
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>
1 parent 311e12b commit 46b92c8

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/node_crypto.cc

+2-10
Original file line numberDiff line numberDiff line change
@@ -5938,11 +5938,7 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) {
59385938

59395939
ClearErrorOnReturn clear_error_on_return;
59405940

5941-
if (args.Length() == 0) {
5942-
return THROW_ERR_MISSING_ARGS(
5943-
env, "Other party's public key argument is mandatory");
5944-
}
5945-
5941+
CHECK_EQ(args.Length(), 1);
59465942
THROW_AND_RETURN_IF_NOT_BUFFER(env, args[0], "Other party's public key");
59475943
ArrayBufferViewContents<unsigned char> key_buf(args[0].As<ArrayBufferView>());
59485944
BignumPointer key(BN_bin2bn(key_buf.data(), key_buf.length(), nullptr));
@@ -5993,11 +5989,7 @@ void DiffieHellman::SetKey(const FunctionCallbackInfo<Value>& args,
59935989

59945990
char errmsg[64];
59955991

5996-
if (args.Length() == 0) {
5997-
snprintf(errmsg, sizeof(errmsg), "%s argument is mandatory", what);
5998-
return THROW_ERR_MISSING_ARGS(env, errmsg);
5999-
}
6000-
5992+
CHECK_EQ(args.Length(), 1);
60015993
if (!Buffer::HasInstance(args[0])) {
60025994
snprintf(errmsg, sizeof(errmsg), "%s must be a buffer", what);
60035995
return THROW_ERR_INVALID_ARG_TYPE(env, errmsg);

0 commit comments

Comments
 (0)