bin/130300: netstat crash when params is incorrect

Li yonggang leeygang at gmail.com
Mon Jan 12 17:10:02 PST 2009


The following reply was made to PR bin/130300; it has been noted by GNATS.

From: "Li yonggang" <leeygang at gmail.com>
To: "Ruslan Ermilov" <ru at freebsd.org>
Cc: bug-followup at freebsd.org
Subject: Re: bin/130300: netstat crash when params is incorrect
Date: Tue, 13 Jan 2009 01:02:06 +0000

 the fix from Ruslan Ermilov works for netstat -m foo.
 but I still think there MUST be a check for illegal params input.
 because in netstat -m foo, the live variable will be set 0 by mistake,
 there is no any reason to continue, because the further call kread
 will use illegal input: foo. we should stop at usage() when illegal
 params input is found. this will apply for all the params input not
 only -m foo, which will help reduce the possibility of the regression
 like -m foo.
 
 %%%
 Index:main.c
 
 =================================================
 --- main.c	2009-01-12 15:13:06.000000000 +0000
 +++ ../main.c	2009-01-12 15:32:14.000000000 +0000
 @@ -341,6 +341,7 @@
  int	af;		/* address family */
  int	live;		/* true if we are examining a live system */
 
 +
  int
  main(int argc, char *argv[])
  {
 @@ -463,28 +464,12 @@
  		default:
  			usage();
  		}
 -	argv += optind;
 -	argc -= optind;
 -
 -#define	BACKWARD_COMPATIBILITY
 -#ifdef	BACKWARD_COMPATIBILITY
 -	if (*argv) {
 -		if (isdigit(**argv)) {
 -			interval = atoi(*argv);
 -			if (interval <= 0)
 -				usage();
 -			++argv;
 -			iflag = 1;
 -		}
 -		if (*argv) {
 -			nlistf = *argv;
 -			if (*++argv)
 -				memf = *argv;
 -		}
 -	}
 -#endif
 -
 -	/*
 +    /*
 +     * Params should be parsed without error.
 +     * */
 +    if(*(argv += optind))
 +        usage();
 +    /*
  	 * Discard setgid privileges if not the running kernel so that bad
  	 * guys can't print interesting stuff from kernel memory.
  	 */
 %%%
 
 Thanks,
 Yonggang Li


More information about the freebsd-bugs mailing list