diff options
author | Milan Broz <gmazyland@gmail.com> | 2022-10-29 11:48:51 +0200 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2022-11-10 18:11:46 +0100 |
commit | 7abe06cbb52cf4c214f8eac1b5f9f3c6a38ed9fa (patch) | |
tree | e0f8de0ed239411fe5f143e34c6f4a4de018a666 /test | |
parent | c8df0736e42b909a158282ffc7c04fec6acd18fe (diff) |
pem: avoid segfault if PKEY is NULL in PEM_write_bio_PrivateKey
Make the code more robust and correctly handle EVP_PKEY set to NULL
instead of dereferencing null pointer.
Signed-off-by: Milan Broz <gmazyland@gmail.com>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19536)
(cherry picked from commit 373d90128042cb0409e347827d80b50a99d3965a)
Diffstat (limited to 'test')
-rw-r--r-- | test/evp_pkey_provided_test.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/test/evp_pkey_provided_test.c b/test/evp_pkey_provided_test.c index 8faf0838d0..d1a287e277 100644 --- a/test/evp_pkey_provided_test.c +++ b/test/evp_pkey_provided_test.c @@ -188,7 +188,12 @@ static int test_print_key_using_pem(const char *alg, const EVP_PKEY *pk) /* Unencrypted private key in PEM form */ || !TEST_true(PEM_write_bio_PrivateKey(membio, pk, NULL, NULL, 0, NULL, NULL)) - || !TEST_true(compare_with_file(alg, PRIV_PEM, membio))) + || !TEST_true(compare_with_file(alg, PRIV_PEM, membio)) + /* NULL key */ + || !TEST_false(PEM_write_bio_PrivateKey(membio, NULL, + NULL, NULL, 0, NULL, NULL)) + || !TEST_false(PEM_write_bio_PrivateKey_traditional(membio, NULL, + NULL, NULL, 0, NULL, NULL))) goto err; ret = 1; |