The x509_name_canon function doesn't check for an error return
authorMatt Caswell <matt@openssl.org>
Thu, 28 Apr 2016 16:05:21 +0000 (17:05 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 29 Apr 2016 15:47:41 +0000 (16:47 +0100)
i2d_name_canon can return a negative number on error. We should check it
before continuing.

Reviewed-by: Rich Salz <rsalz@openssl.org>
crypto/x509/x_name.c

index 5e6abebbea67504bc5cb8755ee2ed4044b42c7dc..cd6c719044ccc6a9870ee189bef00b6b554dda34 100644 (file)
@@ -335,7 +335,7 @@ static int x509_name_canon(X509_NAME *a)
     STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname = NULL;
     STACK_OF(X509_NAME_ENTRY) *entries = NULL;
     X509_NAME_ENTRY *entry, *tmpentry = NULL;
-    int i, set = -1, ret = 0;
+    int i, set = -1, ret = 0, len;
 
     OPENSSL_free(a->canon_enc);
     a->canon_enc = NULL;
@@ -370,7 +370,10 @@ static int x509_name_canon(X509_NAME *a)
 
     /* Finally generate encoding */
 
-    a->canon_enclen = i2d_name_canon(intname, NULL);
+    len = i2d_name_canon(intname, NULL);
+    if (len < 0)
+        goto err;
+    a->canon_enclen = len;
 
     p = OPENSSL_malloc(a->canon_enclen);