diff options
author | slontis <shane.lontis@oracle.com> | 2023-03-21 16:06:06 +1000 |
---|---|---|
committer | Todd Short <todd.short@me.com> | 2023-03-31 15:05:06 -0400 |
commit | 63541ba3b0232047e452ab5d90a4c33a09271cdb (patch) | |
tree | b1b939ab78109737966a2ea0526745086db4ef17 /test | |
parent | 4c507d9d5abbf230e789336e5c37f684208b67da (diff) |
Fix mem leak in ECDSA_sign().
Similiar to the issue found in PR #20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.
Note that this does not affect the higher level EVP
functions as they correctly handle NULL.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/20554)
(cherry picked from commit 4befe81a99b89c52b749a87eece82c1cba4fab12)
(cherry picked from commit 680b4be65eba2658c1d807dd9838ca88301bb7dd)
Diffstat (limited to 'test')
-rw-r--r-- | test/ecdsatest.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ecdsatest.c b/test/ecdsatest.c index 32e929ed3d..375bf2e9ea 100644 --- a/test/ecdsatest.c +++ b/test/ecdsatest.c @@ -346,6 +346,22 @@ static int test_builtin_as_sm2(int n) return test_builtin(n, EVP_PKEY_SM2); } # endif + +static int test_ecdsa_sig_NULL(void) +{ + int ret; + unsigned int siglen; + unsigned char dgst[128] = { 0 }; + EC_KEY *eckey = NULL; + + ret = TEST_ptr(eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1)) + && TEST_int_eq(EC_KEY_generate_key(eckey), 1) + && TEST_int_eq(ECDSA_sign(0, dgst, sizeof(dgst), NULL, &siglen, eckey), 1) + && TEST_int_gt(siglen, 0); + EC_KEY_free(eckey); + return ret; +} + #endif /* OPENSSL_NO_EC */ int setup_tests(void) @@ -365,6 +381,7 @@ int setup_tests(void) return 0; } ADD_ALL_TESTS(test_builtin_as_ec, crv_len); + ADD_TEST(test_ecdsa_sig_NULL); # ifndef OPENSSL_NO_SM2 ADD_ALL_TESTS(test_builtin_as_sm2, crv_len); # endif |