Fix memory leak with crafted X.509 certs
diff --git a/library/x509parse.c b/library/x509parse.c
index 806dcea..c00c5db 100644
--- a/library/x509parse.c
+++ b/library/x509parse.c
@@ -866,6 +866,9 @@
         /* Allocate and assign next pointer */
         if (*p < end)
         {
+            if( cur->next != NULL )
+                return( POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS );
+
             cur->next = (asn1_sequence *) malloc(
                  sizeof( asn1_sequence ) );