RT3061: Don't SEGFAULT when trying to export a public DSA key as a private key.
authorAdam Langley <agl@chromium.org>
Thu, 21 Feb 2013 22:11:55 +0000 (17:11 -0500)
committerEmilia Kasper <emilia@openssl.org>
Fri, 22 Aug 2014 13:21:12 +0000 (15:21 +0200)
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
crypto/dsa/dsa_ameth.c

index cdf49ac862d58ae9fd0e9ae281a669fc6f4ba38a..f89b3c711ca0387129e6a63b31b4a6d3c92c5f07 100644 (file)
@@ -307,6 +307,12 @@ static int dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
        unsigned char *dp = NULL;
        int dplen;
 
+       if (!pkey->pkey.dsa || !pkey->pkey.dsa->priv_key)
+               {
+               DSAerr(DSA_F_DSA_PRIV_ENCODE,DSA_R_MISSING_PARAMETERS);
+               goto err;
+               }
+
        params = ASN1_STRING_new();
 
        if (!params)
@@ -705,4 +711,3 @@ const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[] =
                old_dsa_priv_encode
                }
        };
-