Commit 7836f949c2 for openssl.org

commit 7836f949c2550a00fe2720e96cfaffd824d357d1
Author: Dr. David von Oheimb <David.von.Oheimb@siemens.com>
Date:   Mon Dec 21 15:52:01 2020 +0100

    X509_PUBKEY_set(): Fix error reporting

    Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
    (Merged from https://github.com/openssl/openssl/pull/13658)

diff --git a/crypto/x509/x_pubkey.c b/crypto/x509/x_pubkey.c
index a9beef682b..7423b122d3 100644
--- a/crypto/x509/x_pubkey.c
+++ b/crypto/x509/x_pubkey.c
@@ -99,11 +99,10 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
 {
     X509_PUBKEY *pk = NULL;

-    if (x == NULL)
+    if (x == NULL || pkey == NULL) {
+        ERR_raise(ERR_LIB_X509, ERR_R_PASSED_NULL_PARAMETER);
         return 0;
-
-    if (pkey == NULL)
-        goto unsupported;
+    }

     if (pkey->ameth != NULL) {
         if ((pk = X509_PUBKEY_new()) == NULL) {
@@ -137,8 +136,10 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
         OPENSSL_free(der);
     }

-    if (pk == NULL)
-        goto unsupported;
+    if (pk == NULL) {
+        ERR_raise(ERR_LIB_X509, X509_R_UNSUPPORTED_ALGORITHM);
+        goto error;
+    }

     X509_PUBKEY_free(*x);
     if (!EVP_PKEY_up_ref(pkey)) {
@@ -165,9 +166,6 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
     pk->pkey = pkey;
     return 1;

- unsupported:
-    ERR_raise(ERR_LIB_X509, X509_R_UNSUPPORTED_ALGORITHM);
-
  error:
     X509_PUBKEY_free(pk);
     return 0;