Explorar el Código

plugins/check_http.c - leakage fix

Coverity 66514 - Possible leakage and overflow with addr in redirect functionality. Not confirmed as null terminated, and externally gathered. Restrict string comparisons and duplications by size. - SR
Spenser Reinhardt hace 11 años
padre
commit
e491e5172b
Se han modificado 1 ficheros con 6 adiciones y 4 borrados
  1. 6 4
      plugins/check_http.c

+ 6 - 4
plugins/check_http.c

@@ -1249,6 +1249,7 @@ redir (char *pos, char *status_line)
   if (addr == NULL)
   if (addr == NULL)
     die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate addr\n"));
     die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate addr\n"));
 
 
+  memset(addr, 0, MAX_IPV4_HOSTLENGTH);
   url = malloc (strcspn (pos, "\r\n"));
   url = malloc (strcspn (pos, "\r\n"));
   if (url == NULL)
   if (url == NULL)
     die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate URL\n"));
     die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate URL\n"));
@@ -1339,8 +1340,8 @@ redir (char *pos, char *status_line)
          max_depth, type, addr, i, url, (display_html ? "</A>" : ""));
          max_depth, type, addr, i, url, (display_html ? "</A>" : ""));
 
 
   if (server_port==i &&
   if (server_port==i &&
-      !strcmp(server_address, addr) &&
-      (host_name && !strcmp(host_name, addr)) &&
+      !strncmp(server_address, addr, MAX_IPV4_HOSTLENGTH) &&
+      (host_name && !strncmp(host_name, addr, MAX_IPV4_HOSTLENGTH)) &&
       !strcmp(server_url, url))
       !strcmp(server_url, url))
     die (STATE_WARNING,
     die (STATE_WARNING,
          _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"),
          _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"),
@@ -1349,11 +1350,11 @@ redir (char *pos, char *status_line)
   strcpy (server_type, type);
   strcpy (server_type, type);
 
 
   free (host_name);
   free (host_name);
-  host_name = strdup (addr);
+  host_name = strndup (addr, MAX_IPV4_HOSTLENGTH);
 
 
   if (!(followsticky & STICKY_HOST)) {
   if (!(followsticky & STICKY_HOST)) {
     free (server_address);
     free (server_address);
-    server_address = strdup (addr);
+    server_address = strndup (addr, MAX_IPV4_HOSTLENGTH);
   }
   }
   if (!(followsticky & STICKY_PORT)) {
   if (!(followsticky & STICKY_PORT)) {
     server_port = i;
     server_port = i;
@@ -1372,6 +1373,7 @@ redir (char *pos, char *status_line)
     printf (_("Redirection to %s://%s:%d%s\n"), server_type,
     printf (_("Redirection to %s://%s:%d%s\n"), server_type,
             host_name ? host_name : server_address, server_port, server_url);
             host_name ? host_name : server_address, server_port, server_url);
 
 
+  free(addr);
   check_http ();
   check_http ();
 }
 }