From: Nikos Mavrogiannopoulos Date: Sun, 21 Sep 2008 20:31:07 +0000 (+0300) Subject: fixed memory leak in reencoding of RSA and DSA private keys. Reported and studied... X-Git-Tag: gnutls_2_5_9~32 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=be4dcbb73ea7436649b75279e449fd1e2d4fa437;p=thirdparty%2Fgnutls.git fixed memory leak in reencoding of RSA and DSA private keys. Reported and studied by Sam Varshavchik --- diff --git a/lib/x509/privkey.c b/lib/x509/privkey.c index c8c044f762..3d934676b3 100644 --- a/lib/x509/privkey.c +++ b/lib/x509/privkey.c @@ -1073,6 +1073,13 @@ _gnutls_asn1_encode_rsa (ASN1_TYPE * c2, bigint_t * params) /* Ok. Now we have the data. Create the asn1 structures */ + + /* first make sure that no previously allocated data are leaked */ + if (c2 != ASN1_TYPE_EMPTY) + { + asn1_delete_structure (c2); + c2 = ASN1_TYPE_EMPTY; + } if ((result = asn1_create_element (_gnutls_get_gnutls_asn (), "GNUTLS.RSAPrivateKey", c2)) @@ -1235,6 +1242,13 @@ _gnutls_asn1_encode_dsa (ASN1_TYPE * c2, bigint_t * params) /* Ok. Now we have the data. Create the asn1 structures */ + /* first make sure that no previously allocated data are leaked */ + if (c2 != ASN1_TYPE_EMPTY) + { + asn1_delete_structure (c2); + c2 = ASN1_TYPE_EMPTY; + } + if ((result = asn1_create_element (_gnutls_get_gnutls_asn (), "GNUTLS.DSAPrivateKey", c2)) != ASN1_SUCCESS)