load_pkey_pem: Check for spurious errors when loading
authorTomas Mraz <tomas@openssl.org>
Tue, 29 Jun 2021 14:44:00 +0000 (16:44 +0200)
committerTomas Mraz <tomas@openssl.org>
Fri, 2 Jul 2021 13:33:34 +0000 (15:33 +0200)
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15949)

test/testutil/load.c

index be30d7e05396495c9c557890d1728ba5eb8fc604..d776a7f167cfd5dbe3c41dd5caf8d4fbfc62a34b 100644 (file)
@@ -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;