[Nagiosplug-checkins] CVS: nagiosplug/plugins check_http.c,1.50,1.51

Karl DeBisschop kdebisschop at users.sourceforge.net
Sat Aug 23 08:08:16 CEST 2003


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv2125

Modified Files:
	check_http.c 
Log Message:
- found and fixed memory allocation error in rewritten redir() function


Index: check_http.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_http.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -r1.50 -r1.51
*** check_http.c	23 Aug 2003 13:59:36 -0000	1.50
--- check_http.c	23 Aug 2003 15:07:33 -0000	1.51
***************
*** 476,482 ****
  #endif
  
- 	if (verbose)
- 		printf ("%s://%s:%d%s [%s]\n", server_type, server_address, server_port, server_url, host_name);
- 
  	/* try to connect to the host at the given port number */
  #ifdef HAVE_SSL
--- 476,479 ----
***************
*** 516,522 ****
  	}
  
- 	if (verbose)
- 		printf ("%s://%s:%d%s\n", server_type, server_address, server_port, server_url);
- 
  	/* either send http POST data */
  	if (http_post_data) {
--- 513,516 ----
***************
*** 788,853 ****
  	while (pos) {
  
! 		if (sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i) > 0) {
! 
! 			pos += i;
! 			pos += strspn (pos, " \t\r\n");
  
! 			/* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */
! 			if (sscanf (pos, HD1, type, addr, port, url) == 4) {
! 				use_ssl = server_type_check (type);
! 				i = atoi (port);
! 			}
! 
! 			/* URI_HTTP URI_HOST URI_PATH */
! 			else if (sscanf (pos, HD2, type, addr, url) == 3 ) { 
! 				use_ssl = server_type_check (type);
! 				i = server_port_check (use_ssl);
! 			}
  
! 			/* URI_HTTP URI_HOST URI_PORT */
! 			else if(sscanf (pos, HD3, type, addr, port) == 3) {
! 				strcpy (url, HTTP_URL);
! 				use_ssl = server_type_check (type);
! 				i = atoi (port);
! 			}
  
! 			/* URI_HTTP URI_HOST */
! 			else if(sscanf (pos, HD4, type, addr) == 2) {
! 				strcpy (url, HTTP_URL);
! 				use_ssl = server_type_check (type);
! 				i = server_port_check (use_ssl);
! 			}
  
! 			/* URI_PATH */
! 			else if (sscanf (pos, HD5, url) == 1) {
! 				/* relative url */
! 				if ((url[0] != '/')) {
! 					if ((x = strrchr(url, '/')))
! 						*x = '\0';
! 					asprintf (&server_url, "%s/%s", server_url, url);
! 				}
! 				i = server_port;
! 				strcpy (type, server_type);
! 				strcpy (addr, host_name);
! 			} 					
  
! 			else {
! 				die (STATE_UNKNOWN,
! 						 _("UNKNOWN - Could not parse redirect location - %s%s\n"),
! 						 pos, (display_html ? "</A>" : ""));
! 			}
  
! 			break;
  
! 		} else {
  
! 			pos += (size_t) strcspn (pos, "\r\n");
! 			pos += (size_t) strspn (pos, "\r\n");
! 			if (strlen(pos) == 0) 
! 				die (STATE_UNKNOWN,
! 						 _("UNKNOWN - Could not find redirect location - %s%s\n"),
! 						 status_line, (display_html ? "</A>" : ""));
  
  		}
  
  	} /* end while (pos) */
--- 782,849 ----
  	while (pos) {
  
! 		if (sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i) < 1) {
  
! 			pos += (size_t) strcspn (pos, "\r\n");
! 			pos += (size_t) strspn (pos, "\r\n");
! 			if (strlen(pos) == 0) 
! 				die (STATE_UNKNOWN,
! 						 _("UNKNOWN - Could not find redirect location - %s%s\n"),
! 						 status_line, (display_html ? "</A>" : ""));
! 			continue;
! 		}
  
! 		pos += i;
! 		pos += strspn (pos, " \t\r\n");
  
! 		url = realloc (url, strcspn (pos, "\r\n"));
! 		if (url == NULL)
! 			die (STATE_UNKNOWN, _("ERROR: could not allocate url\n"));
  
! 		/* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */
! 		if (sscanf (pos, HD1, type, addr, port, url) == 4) {
! 			use_ssl = server_type_check (type);
! 			i = atoi (port);
! 		}
  
! 		/* URI_HTTP URI_HOST URI_PATH */
! 		else if (sscanf (pos, HD2, type, addr, url) == 3 ) { 
! 			use_ssl = server_type_check (type);
! 			i = server_port_check (use_ssl);
! 		}
  
! 		/* URI_HTTP URI_HOST URI_PORT */
! 		else if(sscanf (pos, HD3, type, addr, port) == 3) {
! 			strcpy (url, HTTP_URL);
! 			use_ssl = server_type_check (type);
! 			i = atoi (port);
! 		}
  
! 		/* URI_HTTP URI_HOST */
! 		else if(sscanf (pos, HD4, type, addr) == 2) {
! 			strcpy (url, HTTP_URL);
! 			use_ssl = server_type_check (type);
! 			i = server_port_check (use_ssl);
! 		}
  
! 		/* URI_PATH */
! 		else if (sscanf (pos, HD5, url) == 1) {
! 			/* relative url */
! 			if ((url[0] != '/')) {
! 				if ((x = strrchr(url, '/')))
! 					*x = '\0';
! 				asprintf (&server_url, "%s/%s", server_url, url);
! 			}
! 			i = server_port;
! 			strcpy (type, server_type);
! 			strcpy (addr, host_name);
! 		} 					
  
+ 		else {
+ 			die (STATE_UNKNOWN,
+ 					 _("UNKNOWN - Could not parse redirect location - %s%s\n"),
+ 					 pos, (display_html ? "</A>" : ""));
  		}
+ 
+ 		break;
  
  	} /* end while (pos) */





More information about the Commits mailing list