]> git.ipfire.org Git - thirdparty/openssl.git/blobdiff - crypto/asn1/x_x509.c
Fix a failure to NULL a pointer freed on error.
[thirdparty/openssl.git] / crypto / asn1 / x_x509.c
index 018a18bce179233b1e2978934fcaed5d3096452e..d6958f6c1abc23981a4c03216e97984a88d660a9 100644 (file)
@@ -179,8 +179,14 @@ X509 *d2i_X509_AUX(X509 **a, const unsigned char **pp, long length)
 {
     const unsigned char *q;
     X509 *ret;
+    int freeret = 0;
+
     /* Save start position */
     q = *pp;
+
+    if(!a || *a == NULL) {
+        freeret = 1;
+    }
     ret = d2i_X509(a, pp, length);
     /* If certificate unreadable then forget it */
     if (!ret)
@@ -193,7 +199,11 @@ X509 *d2i_X509_AUX(X509 **a, const unsigned char **pp, long length)
         goto err;
     return ret;
  err:
-    X509_free(ret);
+    if(freeret) {
+        X509_free(ret);
+        if (a)
+            *a = NULL;
+    }
     return NULL;
 }