pem_read_bio_key_legacy: Do not obscure real error if there is one
authorTomas Mraz <tomas@openssl.org>
Wed, 19 May 2021 16:16:21 +0000 (18:16 +0200)
committerPauli <pauli@openssl.org>
Fri, 21 May 2021 00:03:07 +0000 (10:03 +1000)
Fixes #15170

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15355)

crypto/pem/pem_pkey.c

index 3f0a9e4fefce8087ae3f65c56b8fcd432d1c7947..adbf8bcfe70413b936f81bb3714875b1f511d79b 100644 (file)
@@ -171,7 +171,8 @@ static EVP_PKEY *pem_read_bio_key_legacy(BIO *bp, EVP_PKEY **x,
     }
 
  p8err:
-    if (ret == NULL)
+    if (ret == NULL && ERR_peek_last_error() == 0)
+        /* ensure some error is reported but do not hide the real one */
         ERR_raise(ERR_LIB_PEM, ERR_R_ASN1_LIB);
  err:
     OPENSSL_secure_free(nm);