]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
fixed memory leak in reencoding of RSA and DSA private keys. Reported and studied...
authorNikos Mavrogiannopoulos <nmav@turtle.(none)>
Sun, 21 Sep 2008 20:31:07 +0000 (23:31 +0300)
committerNikos Mavrogiannopoulos <nmav@turtle.(none)>
Sun, 21 Sep 2008 20:31:07 +0000 (23:31 +0300)
lib/x509/privkey.c

index c8c044f762a1179fa8660d587fa7bafbbf4e7d46..3d934676b3f0b07c0113119b4a9304c6ed4bd190 100644 (file)
@@ -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)