[Nagiosplug-checkins] CVS: nagiosplug/plugins utils.c,1.13,1.14

Karl DeBisschop kdebisschop at users.sourceforge.net
Thu Jan 2 19:25:02 CET 2003


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

Modified Files:
	utils.c 
Log Message:
protect against some null strings, make formats more uniform

Index: utils.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** utils.c	18 Nov 2002 07:22:28 -0000	1.13
--- utils.c	3 Jan 2003 03:24:17 -0000	1.14
***************
*** 166,169 ****
--- 166,172 ----
  	char c[1];
  
+ 	if (!address)
+ 		return FALSE;
+ 
  	if (sscanf (address, "%d.%d.%d.%d%c", &o1, &o2, &o3, &o4, c) != 4)
  		return FALSE;
***************
*** 186,201 ****
  is_hostname (char *s1)
  {
! 	if (strlen (s1) > 63)
  		return FALSE;
! 	if (strcspn
! 			(s1,
! 			 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUWVXYZ0123456789-.") !=
! 			0) return FALSE;
! 	if (strspn (s1, "0123456789-.") == 1)
  		return FALSE;
  	while ((s1 = index (s1, '.'))) {
  		s1++;
  		if (strspn (s1, "0123456789-.") == 1) {
- 			printf ("%s\n", s1);
  			return FALSE;
  		}
--- 189,204 ----
  is_hostname (char *s1)
  {
! 	if (!s1 || strlen (s1) > 63) {
! 		return FALSE;
! 	}
! 	if (strcspn (s1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUWVXYZ0123456789-.") !=	0) {
  		return FALSE;
! 	}
! 	if (strspn (s1, "0123456789-.") == 1) {
  		return FALSE;
+ 	}
  	while ((s1 = index (s1, '.'))) {
  		s1++;
  		if (strspn (s1, "0123456789-.") == 1) {
  			return FALSE;
  		}
***************
*** 209,215 ****
  	char tmp[1];
  	float x;
! 	if (sscanf (number, "%f%c", &x, tmp) == 1)
! 		return (TRUE);
! 	return (FALSE);
  }
  
--- 212,222 ----
  	char tmp[1];
  	float x;
! 
! 	if (!number)
! 		return FALSE;
! 	else if (sscanf (number, "%f%c", &x, tmp) == 1)
! 		return TRUE;
! 	else
! 		return FALSE;
  }
  
***************
*** 218,223 ****
  {
  	if (is_numeric (number) && atof (number) > 0.0)
! 		return (TRUE);
! 	return (FALSE);
  }
  
--- 225,231 ----
  {
  	if (is_numeric (number) && atof (number) > 0.0)
! 		return TRUE;
! 	else
! 		return FALSE;
  }
  
***************
*** 226,231 ****
  {
  	if (is_numeric (number) && atof (number) < 0.0)
! 		return (TRUE);
! 	return (FALSE);
  }
  
--- 234,240 ----
  {
  	if (is_numeric (number) && atof (number) < 0.0)
! 		return TRUE;
! 	else
! 		return FALSE;
  }
  
***************
*** 234,239 ****
  {
  	if (is_numeric (number) && atof (number) >= 0.0)
! 		return (TRUE);
! 	return (FALSE);
  }
  
--- 243,249 ----
  {
  	if (is_numeric (number) && atof (number) >= 0.0)
! 		return TRUE;
! 	else
! 		return FALSE;
  }
  
***************
*** 243,248 ****
  	int x;
  	if (is_numeric (number) && (x = atof (number)) >= 0 && x <= 100)
! 		return (TRUE);
! 	return (FALSE);
  }
  
--- 253,259 ----
  	int x;
  	if (is_numeric (number) && (x = atof (number)) >= 0 && x <= 100)
! 		return TRUE;
! 	else
! 		return FALSE;
  }
  
***************
*** 252,262 ****
  	long int n;
  
! 	if (strspn (number, "-0123456789 ") != strlen (number))
! 		return (FALSE);
  
  	n = strtol (number, NULL, 10);
  	if (errno != ERANGE && n >= INT_MIN && n <= INT_MAX)
! 		return (TRUE);
! 	return (FALSE);
  }
  
--- 263,275 ----
  	long int n;
  
! 	if (!number || (strspn (number, "-0123456789 ") != strlen (number)))
! 		return FALSE;
  
  	n = strtol (number, NULL, 10);
+ 
  	if (errno != ERANGE && n >= INT_MIN && n <= INT_MAX)
! 		return TRUE;
! 	else
! 		return FALSE;
  }
  
***************
*** 265,270 ****
  {
  	if (is_integer (number) && atoi (number) > 0)
! 		return (TRUE);
! 	return (FALSE);
  }
  
--- 278,284 ----
  {
  	if (is_integer (number) && atoi (number) > 0)
! 		return TRUE;
! 	else
! 		return FALSE;
  }
  
***************
*** 273,278 ****
  {
  	if (is_integer (number) && atoi (number) < 0)
! 		return (TRUE);
! 	return (FALSE);
  }
  
--- 287,293 ----
  {
  	if (is_integer (number) && atoi (number) < 0)
! 		return TRUE;
! 	else
! 		return FALSE;
  }
  
***************
*** 281,286 ****
  {
  	if (is_integer (number) && atoi (number) >= 0)
! 		return (TRUE);
! 	return (FALSE);
  }
  
--- 296,302 ----
  {
  	if (is_integer (number) && atoi (number) >= 0)
! 		return TRUE;
! 	else
! 		return FALSE;
  }
  
***************
*** 290,295 ****
  	int i;
  	if (is_integer (number) && (i = atoi (number)) >= 0 && i <= 100)
! 		return (TRUE);
! 	return (FALSE);
  }
  
--- 306,312 ----
  	int i;
  	if (is_integer (number) && (i = atoi (number)) >= 0 && i <= 100)
! 		return TRUE;
! 	else
! 		return FALSE;
  }
  
***************
*** 297,303 ****
  is_option (char *str)
  {
! 	if (strspn (str, "-") == 1 || strspn (str, "-") == 2)
  		return TRUE;
! 	return FALSE;
  }
  
--- 314,323 ----
  is_option (char *str)
  {
! 	if (!str)
! 		return FALSE;
! 	else if (strspn (str, "-") == 1 || strspn (str, "-") == 2)
  		return TRUE;
! 	else
! 		return FALSE;
  }
  





More information about the Commits mailing list