]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
_decode_pkcs8_dsa_key: fixed memory leak on error path
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 4 Jan 2017 08:32:17 +0000 (09:32 +0100)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 4 Jan 2017 12:41:43 +0000 (13:41 +0100)
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
lib/x509/privkey_pkcs8.c

index f7ada0234b58156bb2d6abf64a2cf6ae2d4f35d6..4e1e2686e202c7b823e567fdc144799bcbd1e6ef 100644 (file)
@@ -1025,6 +1025,9 @@ _decode_pkcs8_dsa_key(ASN1_TYPE pkcs8_asn, gnutls_x509_privkey_t pkey)
                goto error;
        }
 
+       pkey->params.algo = GNUTLS_PK_DSA;
+       pkey->params.params_nr = DSA_PRIVATE_PARAMS;
+
        ret =
            _gnutls_asn1_encode_privkey(GNUTLS_PK_DSA, &pkey->key,
                                        &pkey->params, pkey->flags&GNUTLS_PRIVKEY_FLAG_EXPORT_COMPAT);
@@ -1033,12 +1036,11 @@ _decode_pkcs8_dsa_key(ASN1_TYPE pkcs8_asn, gnutls_x509_privkey_t pkey)
                goto error;
        }
 
-       pkey->params.algo = GNUTLS_PK_DSA;
-       pkey->params.params_nr = DSA_PRIVATE_PARAMS;
-
-       ret = 0;
+       return 0;
 
-      error:
+ error:
+       if (pkey->params.params_nr != DSA_PRIVATE_PARAMS)
+               _gnutls_mpi_release(&pkey->params.params[4]);
        return ret;
 }