From bb8a24503c309e353fb25f341de3ed27f7003f77 Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Tue, 29 Jun 2021 16:44:00 +0200 Subject: [PATCH] load_pkey_pem: Check for spurious errors when loading Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/15949) --- test/testutil/load.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/testutil/load.c b/test/testutil/load.c index be30d7e0539..d776a7f167c 100644 --- a/test/testutil/load.c +++ b/test/testutil/load.c @@ -73,9 +73,17 @@ EVP_PKEY *load_pkey_pem(const char *file, OSSL_LIB_CTX *libctx) if (!TEST_ptr(file) || !TEST_ptr(bio = BIO_new(BIO_s_file()))) return NULL; - if (TEST_int_gt(BIO_read_filename(bio, file), 0)) - (void)TEST_ptr(key = PEM_read_bio_PrivateKey_ex(bio, NULL, NULL, NULL, - libctx, NULL)); + if (TEST_int_gt(BIO_read_filename(bio, file), 0)) { + unsigned long err = ERR_peek_error(); + + if (TEST_ptr(key = PEM_read_bio_PrivateKey_ex(bio, NULL, NULL, NULL, + libctx, NULL)) + && err != ERR_peek_error()) { + TEST_info("Spurious error from reading PEM"); + EVP_PKEY_free(key); + key = NULL; + } + } BIO_free(bio); return key; -- 2.47.3