]> granicus.if.org Git - mutt/commitdiff
gnutls:tls_compare_certificates: check strstr for failure (closes #3547)
authorBrendan Cully <brendan@kublai.com>
Mon, 9 Jul 2012 00:25:12 +0000 (17:25 -0700)
committerBrendan Cully <brendan@kublai.com>
Mon, 9 Jul 2012 00:25:12 +0000 (17:25 -0700)
A malformed certificate file could cause strstr to return an unhandled NULL.
Thanks to hhorak for the proposed patch. This one is similar but avoids using
memmem for the first time (I am not sure about its portability).

mutt_ssl_gnutls.c

index d670c4338cef9bfbf29d99992aaaa33724e3c61c..e2b0f082268ce54d9554a71323a453517d7cdc8b 100644 (file)
@@ -439,8 +439,16 @@ static int tls_compare_certificates (const gnutls_datum *peercert)
       return 0;
     }
 
-    ptr = (unsigned char *)strstr((char*)b64_data.data, CERT_SEP) + 1;
-    ptr = (unsigned char *)strstr((char*)ptr, CERT_SEP);
+    /* find start of cert, skipping junk */
+    ptr = (unsigned char *)strstr((char*)b64_data.data, CERT_SEP);
+    if (!ptr)
+    {
+      gnutls_free(cert.data);
+      FREE (&b64_data_data);
+      return 0;
+    }
+    /* find start of next cert */
+    ptr = (unsigned char *)strstr((char*)ptr + 1, CERT_SEP);
 
     b64_data.size = b64_data.size - (ptr - b64_data.data);
     b64_data.data = ptr;