Blame SOURCES/net-snmp-5.8-fix-cert-crash.patch

6af263
diff -urNp a/snmplib/snmp_openssl.c b/snmplib/snmp_openssl.c
6af263
--- a/snmplib/snmp_openssl.c	2021-06-09 12:38:23.196037329 +0200
6af263
+++ b/snmplib/snmp_openssl.c	2021-06-09 12:44:11.782503048 +0200
6af263
@@ -284,31 +284,30 @@ _cert_get_extension(X509_EXTENSION  *oex
6af263
     }
6af263
     if (X509V3_EXT_print(bio, oext, 0, 0) != 1) {
6af263
         snmp_log(LOG_ERR, "could not print extension!\n");
6af263
-        BIO_vfree(bio);
6af263
-        return NULL;
6af263
+        goto out;
6af263
     }
6af263
 
6af263
     space = BIO_get_mem_data(bio, &data);
6af263
     if (buf && *buf) {
6af263
-        if (*len < space) 
6af263
-            buf_ptr = NULL;
6af263
-        else
6af263
-            buf_ptr = *buf;
6af263
+        if (*len < space +1) {
6af263
+            snmp_log(LOG_ERR, "not enough buffer space to print extension\n"); 
6af263
+            goto out;
6af263
+        }
6af263
+        buf_ptr = *buf;    
6af263
+    } else {
6af263
+        buf_ptr = calloc(1, space + 1);
6af263
     }
6af263
-    else
6af263
-        buf_ptr = calloc(1,space + 1);
6af263
     
6af263
     if (!buf_ptr) {
6af263
-        snmp_log(LOG_ERR,
6af263
-                 "not enough space or error in allocation for extenstion\n");
6af263
-        BIO_vfree(bio);
6af263
-        return NULL;
6af263
+        snmp_log(LOG_ERR, "error in allocation for extenstion\n");
6af263
+        goto out;
6af263
     }
6af263
     memcpy(buf_ptr, data, space);
6af263
     buf_ptr[space] = 0;
6af263
     if (len)
6af263
         *len = space;
6af263
 
6af263
+out:
6af263
     BIO_vfree(bio);
6af263
 
6af263
     return buf_ptr;
6af263
@@ -479,7 +478,7 @@ netsnmp_openssl_cert_dump_extensions(X50
6af263
 {
6af263
     X509_EXTENSION  *extension;
6af263
     const char      *extension_name;
6af263
-    char             buf[SNMP_MAXBUF_SMALL], *buf_ptr = buf, *str, *lf;
6af263
+    char             buf[SNMP_MAXBUF], *buf_ptr = buf, *str, *lf;
6af263
     int              i, num_extensions, buf_len, nid;
6af263
 
6af263
     if (NULL == ocert)
6af263
@@ -499,6 +498,11 @@ netsnmp_openssl_cert_dump_extensions(X50
6af263
         extension_name = OBJ_nid2sn(nid);
6af263
         buf_len = sizeof(buf);
6af263
         str = _cert_get_extension_str_at(ocert, i, &buf_ptr, &buf_len, 0);
6af263
+        if (!str) {
6af263
+            DEBUGMSGT(("9:cert:dump", "    %2d: %s\n", i,
6af263
+                        extension_name));
6af263
+            continue;
6af263
+        }
6af263
         lf = strchr(str, '\n'); /* look for multiline strings */
6af263
         if (NULL != lf)
6af263
             *lf = '\0'; /* only log first line of multiline here */