Explorar el Código

Update host_name if port specified.

If a port is specified this fails. The host_name needs to be updated since the socket/connect calls require an IP/DNS string with the port specified separately to be valid.
Isaac A. White hace 6 años
padre
commit
49afbd5fb9
Se han modificado 1 ficheros con 8 adiciones y 4 borrados
  1. 8 4
      plugins/check_http.c

+ 8 - 4
plugins/check_http.c

@@ -426,13 +426,17 @@ enable_ssl:
             break;
             /* Note: H, I, and u must be malloc'd or will fail on redirects */
         case 'H': /* Host Name (virtual host) */
-            host_name = strdup (optarg);
-            if (host_name[0] == '[') {
-                if ((p = strstr (host_name, "]:")) != NULL) /* [IPv6]:port */
+            host_name = strdup(optarg);
+            if (*host_name == '[') {
+                if ((p = strstr (host_name, "]:")) != NULL) /* [IPv6]:port */ {
                     server_port = atoi (p + 2);
+                    *++p = '\0'; // Set The host_name sans ":port"
+                }
             } else if ((p = strchr (host_name, ':')) != NULL
-                       && strchr (++p, ':') == NULL) /* IPv4:port or host:port */
+                       && strchr (++p, ':') == NULL) /* IPv4:port or host:port */ {
                 server_port = atoi (p);
+                *--p = '\0'; // Set The host_name sans ":port"
+            }
             break;
         case 'I': /* Server IP-address */
             server_address = strdup (optarg);