Browse Source

check_http - Memory allocation error

Fix for issue #235
John C. Frickson 8 years ago
parent
commit
4836716052
2 changed files with 11 additions and 6 deletions
  1. 1 0
      NEWS
  2. 10 6
      plugins/check_http.c

+ 1 - 0
NEWS

@@ -26,6 +26,7 @@ This file documents the major additions and syntax changes between releases.
 	check_mailq: Nullmailer Regex is not working for Ubuntu 16.04
 	check_swap: Downstream Fedora patch: Prevent check_swap from returning OK, if no swap activated
 	Building RPMs on Amazon Linux - Add 'install-root' on line 165 of spec file
+	check_http: Memory allocation error
 
 
 2.2.0 2017-01-19

+ 10 - 6
plugins/check_http.c

@@ -1134,15 +1134,19 @@ check_http (void)
       elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6;
     }
     buffer[i] = '\0';
-    xasprintf (&full_page_new, "%s%s", full_page, buffer);
-    free (full_page);
+    /* xasprintf (&full_page_new, "%s%s", full_page, buffer); */
+		if ((full_page_new = realloc(full_page, pagesize + i + 1)) == NULL)
+			die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate memory for full_page\n"));
+
+		memmove(&full_page_new[pagesize], buffer, i);
+    /*free (full_page);*/
     full_page = full_page_new;
     pagesize += i;
 
-                if (no_body && document_headers_done (full_page)) {
-                  i = 0;
-                  break;
-                }
+    if (no_body && document_headers_done (full_page)) {
+      i = 0;
+      break;
+    }
   }
   microsec_transfer = deltime (tv_temp);
   elapsed_time_transfer = (double)microsec_transfer / 1.0e6;