4
0
Эх сурвалжийг харах

check_http segmentation fault (FreeBSD)

Fix for issue https://github.com/nagios-plugins/nagios-plugins/issues/104
John C. Frickson 9 жил өмнө
parent
commit
33d42b197f
2 өөрчлөгдсөн 6 нэмэгдсэн , 4 устгасан
  1. 1 0
      NEWS
  2. 5 4
      plugins/netutils.c

+ 1 - 0
NEWS

@@ -5,6 +5,7 @@ This file documents the major additions and syntax changes between releases.
 	check_http - Don't include default Accept header if one is provided
 	check_disk - added "fuse.gvfsd-fuse" to list of fs types to ignore
 	check_http - Fixed non-text chunked-encoded decoding
+	check_http - segmentation fault (FreeBSD)
 
 
 2.1.3 2016-09-12

+ 5 - 4
plugins/netutils.c

@@ -179,7 +179,7 @@ int
 np_net_connect (const char *host_name, int port, int *sd, int proto)
 {
 	struct addrinfo hints;
-	struct addrinfo *res;
+	struct addrinfo *res, *orig_res;
 	struct sockaddr_un su;
 	char port_str[6], host[MAX_HOST_ADDRESS_LENGTH];
 	size_t len;
@@ -206,7 +206,7 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
 		memcpy (host, host_name, len);
 		host[len] = '\0';
 		snprintf (port_str, sizeof (port_str), "%d", port);
-		result = getaddrinfo (host, port_str, &hints, &res);
+		result = getaddrinfo (host, port_str, &hints, &orig_res);
 
 		if (result != 0) {
 			if (result == EAI_NONAME)
@@ -216,13 +216,14 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
 			return STATE_UNKNOWN;
 		}
 
+		res = orig_res;
 		while (res) {
 			/* attempt to create a socket */
 			*sd = socket (res->ai_family, socktype, res->ai_protocol);
 
 			if (*sd < 0) {
 				printf ("%s\n", _("Socket creation failed"));
-				freeaddrinfo (res);
+				freeaddrinfo (orig_res);
 				return STATE_UNKNOWN;
 			}
 
@@ -245,7 +246,7 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
 			close (*sd);
 			res = res->ai_next;
 		}
-		freeaddrinfo (res);
+		freeaddrinfo (orig_res);
 	}
 	/* else the hostname is interpreted as a path to a unix socket */
 	else {