Avoid out-of-bounds read
authorRich Salz <rsalz@openssl.org>
Tue, 22 Aug 2017 15:44:41 +0000 (11:44 -0400)
committerRich Salz <rsalz@openssl.org>
Mon, 28 Aug 2017 17:33:54 +0000 (13:33 -0400)
Fixes CVE 2017-3735

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/4276)

(cherry picked from commit b23171744b01e473ebbfd6edad70c1c3825ffbcd)

crypto/x509v3/v3_addr.c

index ef1d775ac938acf96b8d3343ee1321d9f80a8bf7..c5183a1790717a1f75015856a90639f980dac0f8 100644 (file)
@@ -84,10 +84,12 @@ static int length_from_afi(const unsigned afi)
  */
 unsigned int X509v3_addr_get_afi(const IPAddressFamily *f)
 {
-    return ((f != NULL &&
-             f->addressFamily != NULL && f->addressFamily->data != NULL)
-            ? ((f->addressFamily->data[0] << 8) | (f->addressFamily->data[1]))
-            : 0);
+    if (f == NULL
+            || f->addressFamily == NULL
+            || f->addressFamily->data == NULL
+            || f->addressFamily->length < 2)
+        return 0;
+    return (f->addressFamily->data[0] << 8) | f->addressFamily->data[1];
 }
 
 /*