From 199545279745089255f60ee3ec7b549e479722ca Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Wed, 6 Dec 2017 08:09:02 +0100 Subject: [PATCH 1/2] crypto: declare int return type for set_field This commit updates the set_field function pointer to return an int, and also updates the lambdas with a return statement. --- src/node_crypto.cc | 10 ++++++---- src/node_crypto.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index b5b0e4e21cbb2e..43768c42cf13b2 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5084,7 +5084,7 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo& args) { } void DiffieHellman::SetKey(const v8::FunctionCallbackInfo& args, - void (*set_field)(DH*, BIGNUM*), const char* what) { + int (*set_field)(DH*, BIGNUM*), const char* what) { Environment* env = Environment::GetCurrent(args); DiffieHellman* dh; @@ -5107,12 +5107,13 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo& args, BN_bin2bn(reinterpret_cast(Buffer::Data(args[0])), Buffer::Length(args[0]), nullptr); CHECK_NE(num, nullptr); - set_field(dh->dh, num); + USE(set_field(dh->dh, num)); } void DiffieHellman::SetPublicKey(const FunctionCallbackInfo& args) { - SetKey(args, [](DH* dh, BIGNUM* num) { DH_set0_key(dh, num, nullptr); }, + SetKey(args, + [](DH* dh, BIGNUM* num) { return DH_set0_key(dh, num, nullptr); }, "Public key"); } @@ -5123,7 +5124,8 @@ void DiffieHellman::SetPrivateKey(const FunctionCallbackInfo& args) { // Node. See https://github.com/openssl/openssl/pull/4384. #error "OpenSSL 1.1.0 revisions before 1.1.0g are not supported" #endif - SetKey(args, [](DH* dh, BIGNUM* num) { DH_set0_key(dh, nullptr, num); }, + SetKey(args, + [](DH* dh, BIGNUM* num) { return DH_set0_key(dh, nullptr, num); }, "Private key"); } diff --git a/src/node_crypto.h b/src/node_crypto.h index 836144bf8be1a2..7d8c9032c65285 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -712,7 +712,7 @@ class DiffieHellman : public BaseObject { const BIGNUM* (*get_field)(const DH*), const char* err_if_null); static void SetKey(const v8::FunctionCallbackInfo& args, - void (*set_field)(DH*, BIGNUM*), const char* what); + int (*set_field)(DH*, BIGNUM*), const char* what); bool VerifyContext(); bool initialised_; From 0a1bfc14c024ed8c721416d217357c55332472f5 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 7 Dec 2017 07:44:08 +0100 Subject: [PATCH 2/2] squash: add check of return value --- src/node_crypto.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 43768c42cf13b2..04fd9bf9568bf0 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5107,7 +5107,7 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo& args, BN_bin2bn(reinterpret_cast(Buffer::Data(args[0])), Buffer::Length(args[0]), nullptr); CHECK_NE(num, nullptr); - USE(set_field(dh->dh, num)); + CHECK_EQ(1, set_field(dh->dh, num)); }