From: Tomas Mraz Date: Tue, 29 Jun 2021 14:44:00 +0000 (+0200) Subject: load_pkey_pem: Check for spurious errors when loading X-Git-Tag: openssl-3.0.0-beta2~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb8a24503c309e353fb25f341de3ed27f7003f77;p=thirdparty%2Fopenssl.git load_pkey_pem: Check for spurious errors when loading Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/15949) --- 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;