[Nagiosplug-checkins] CVS: nagiosplug/plugins check_smtp.c,1.6,1.7

Karl DeBisschop kdebisschop at users.sourceforge.net
Wed Oct 30 10:30:02 CET 2002


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory usw-pr-cvs1:/tmp/cvs-serv26382/plugins

Modified Files:
	check_smtp.c 
Log Message:
remove call_getopt, fix several buffer overruns possible due to use of fixed size buffers

Index: check_smtp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_smtp.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** check_smtp.c	2 Sep 2002 18:47:07 -0000	1.6
--- check_smtp.c	30 Oct 2002 18:29:07 -0000	1.7
***************
*** 62,68 ****
  
  int process_arguments (int, char **);
- int call_getopt (int, char **);
  int validate_arguments (void);
- int check_disk (int usp, int free_disk);
  void print_help (void);
  void print_usage (void);
--- 62,66 ----
***************
*** 81,91 ****
  main (int argc, char **argv)
  {
! 	int sd;
  	int result;
  	char buffer[MAX_INPUT_BUFFER] = "";
! 	char helocmd[255] = SMTP_HELO ;
! 	char from_str[255] = SMTP_DUMMYCMD ;
! 	char myhostname[248];
! 	
  
  	if (process_arguments (argc, argv) != OK)
--- 79,87 ----
  main (int argc, char **argv)
  {
! 	int sd, c;
  	int result;
  	char buffer[MAX_INPUT_BUFFER] = "";
! 	char *from_str = NULL;
! 	char *helocmd = NULL;
  
  	if (process_arguments (argc, argv) != OK)
***************
*** 93,113 ****
  
  	/* initialize the HELO command with the localhostname */
! 	gethostname(myhostname, sizeof(myhostname));
! 	strcat(helocmd, myhostname);
! 	strcat(helocmd, "\r\n");
  
  	/* initialize the MAIL command with optional FROM command  */
! 	if (from_arg) {
! 		strcat(from_str, "FROM: ");
! 		strcat(from_str, from_arg);
! 	}
! 	/* terminate line with a CRLF */
! 	strcat(from_str, "\r\n");
! 		
! 	if (verbose == TRUE){
! 		printf ("FROMCMD: %s\n", from_str);
! 	}
  
! 	
  	
  	/* initialize alarm signal handling */
--- 89,104 ----
  
  	/* initialize the HELO command with the localhostname */
! #ifndef HOST_MAX_BYTES
! #define HOST_MAX_BYTES 255
! #endif
! 	helocmd = malloc (HOST_MAX_BYTES);
! 	gethostname(helocmd, HOST_MAX_BYTES);
! 	asprintf (&helocmd, "%s%s%s", SMTP_HELO, helocmd, "\r\n");
  
  	/* initialize the MAIL command with optional FROM command  */
! 	asprintf (&from_str, "%sFROM: %s%s", SMTP_DUMMYCMD, from_arg, "\r\n");
  
! 	if (verbose == TRUE)
! 		printf ("FROMCMD: %s\n", from_str);
  	
  	/* initialize alarm signal handling */
***************
*** 171,189 ****
  
  		/* close the connection */
  		/* first send the HELO command */
! 		send(sd,helocmd,strlen(helocmd),0);
  		/* allow for response to helo command to reach us */
! 		recv(sd,buffer,MAX_INPUT_BUFFER-1,0);
  				
  #ifdef SMTP_USE_DUMMYCMD
! 		send(sd,from_str,strlen(from_str),0);
  		/* allow for response to DUMMYCMD to reach us */
! 		recv(sd,buffer,MAX_INPUT_BUFFER-1,0);
  		if (verbose == TRUE) 
! 			printf("DUMMYCMD: %s\n%s\n",from_str,buffer);		
  #endif /* SMTP_USE_DUMMYCMD */
  
! 		/* finally close the connection */
  		send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0);
  		close (sd);
  	}
--- 162,186 ----
  
  		/* close the connection */
+ 
  		/* first send the HELO command */
! 		send(sd, helocmd, strlen(helocmd), 0);
! 
  		/* allow for response to helo command to reach us */
! 		recv(sd, buffer, MAX_INPUT_BUFFER-1, 0);
  				
  #ifdef SMTP_USE_DUMMYCMD
! 		send(sd, from_str, strlen(from_str), 0);
! 
  		/* allow for response to DUMMYCMD to reach us */
! 		recv(sd, buffer, MAX_INPUT_BUFFER-1, 0);
! 
  		if (verbose == TRUE) 
! 			printf("DUMMYCMD: %s\n%s\n",from_str,buffer);
  #endif /* SMTP_USE_DUMMYCMD */
  
! 		/* tell the server we're done */
  		send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0);
+ 
+ 		/* finally close the connection */
  		close (sd);
  	}
***************
*** 206,258 ****
  	int c;
  
- 	if (argc < 2)
- 		return ERROR;
- 
- 	for (c = 1; c < argc; c++) {
- 		if (strcmp ("-to", argv[c]) == 0)
- 			strcpy (argv[c], "-t");
- 		else if (strcmp ("-wt", argv[c]) == 0)
- 			strcpy (argv[c], "-w");
- 		else if (strcmp ("-ct", argv[c]) == 0)
- 			strcpy (argv[c], "-c");
- 	}
- 
- 
- 
- 	c = 0;
- 	while ((c += (call_getopt (argc - c, &argv[c]))) < argc) {
- 
- 		if (is_option (argv[c]))
- 			continue;
- 
- 		if (server_address == NULL) {
- 			if (is_host (argv[c])) {
- 				server_address = argv[c];
- 			}
- 			else {
- 				usage ("Invalid host name");
- 			}
- 		}
- 	}
- 
- 	if (server_address == NULL)
- 		server_address = strscpy (NULL, "127.0.0.1");
- 
- 	if (server_expect == NULL)
- 		server_expect = strscpy (NULL, SMTP_EXPECT);
- 
- 	return validate_arguments ();
- }
- 
- 
- 
- 
- 
- 
- int
- call_getopt (int argc, char **argv)
- {
- 	int c, i = 0;
- 
  #ifdef HAVE_GETOPT_H
  	int option_index = 0;
--- 203,206 ----
***************
*** 271,274 ****
--- 219,234 ----
  #endif
  
+ 	if (argc < 2)
+ 		return ERROR;
+ 
+ 	for (c = 1; c < argc; c++) {
+ 		if (strcmp ("-to", argv[c]) == 0)
+ 			strcpy (argv[c], "-t");
+ 		else if (strcmp ("-wt", argv[c]) == 0)
+ 			strcpy (argv[c], "-w");
+ 		else if (strcmp ("-ct", argv[c]) == 0)
+ 			strcpy (argv[c], "-c");
+ 	}
+ 
  	while (1) {
  #ifdef HAVE_GETOPT_H
***************
*** 279,300 ****
  		c = getopt (argc, argv, "+?hVvt:p:f:e:c:w:H:");
  #endif
! 
! 		i++;
! 
! 		if (c == -1 || c == EOF || c == 1)
  			break;
  
  		switch (c) {
- 		case 't':
- 		case 'p':
- 		case 'e':
- 		case 'f':
- 		case 'c':
- 		case 'w':
- 		case 'H':
- 			i++;
- 		}
- 
- 		switch (c) {
  		case 'H':									/* hostname */
  			if (is_host (optarg)) {
--- 239,246 ----
  		c = getopt (argc, argv, "+?hVvt:p:f:e:c:w:H:");
  #endif
! 		if (c == -1 || c == EOF)
  			break;
  
  		switch (c) {
  		case 'H':									/* hostname */
  			if (is_host (optarg)) {
***************
*** 358,362 ****
  		}
  	}
! 	return i;
  }
  
--- 304,325 ----
  		}
  	}
! 
! 	c = optind;
! 	if (server_address == NULL) {
! 		if (argv[c]) {
! 			if (is_host (argv[c]))
! 				server_address = argv[c];
! 			else
! 				usage ("Invalid host name");
! 		}
! 		else {
! 			asprintf (&server_address, "127.0.0.1");
! 		}
! 	}
! 
! 	if (server_expect == NULL)
! 		asprintf (&server_expect, SMTP_EXPECT);
! 
! 	return validate_arguments ();
  }
  





More information about the Commits mailing list