Add size limit to X509_NAME structure.
authorDr. Stephen Henson <steve@openssl.org>
Thu, 28 Apr 2016 11:55:29 +0000 (12:55 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Fri, 29 Apr 2016 18:42:21 +0000 (19:42 +0100)
This adds an explicit limit to the size of an X509_NAME structure. Some
part of OpenSSL (e.g. TLS) already effectively limit the size due to
restrictions on certificate size.

Reviewed-by: Matt Caswell <matt@openssl.org>
crypto/x509/x_name.c

index cd6c719044ccc6a9870ee189bef00b6b554dda34..72682fed70d4337b7aacd6a8a02e22c97493eef8 100644 (file)
 #include "internal/asn1_int.h"
 #include "x509_lcl.h"
 
+/*
+ * Maximum length of X509_NAME: much larger than anything we should
+ * ever see in practice.
+ */
+
+#define X509_NAME_MAX (1024 * 1024)
+
 static int x509_name_ex_d2i(ASN1_VALUE **val,
                             const unsigned char **in, long len,
                             const ASN1_ITEM *it,
@@ -187,6 +194,10 @@ static int x509_name_ex_d2i(ASN1_VALUE **val,
     int i, j, ret;
     STACK_OF(X509_NAME_ENTRY) *entries;
     X509_NAME_ENTRY *entry;
+    if (len > X509_NAME_MAX) {
+        ASN1err(ASN1_F_X509_NAME_EX_D2I, ASN1_R_TOO_LONG);
+        return 0;
+    }
     q = p;
 
     /* Get internal representation of Name */