Subject: bin/850: systat core dumps if given invalid option
To: None <gnats-admin@NetBSD.ORG>
From: None <sh391@city.ac.uk>
List: netbsd-bugs
Date: 03/08/1995 02:20:06
>Number:         850
>Category:       bin
>Synopsis:       systat core dumps if given invalid option
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar  8 02:20:04 1995
>Originator:     David Brownlee
>Organization:
Private
>Release:        feb 95
>Environment:
sparc, 1.0A, current
System: NetBSD gluon.city.ac.uk 1.0A NetBSD 1.0A (GLUON) #1: Thu Feb 9 11:25:40 GMT 1995 monoadm@gluon.city.ac.uk:/mono/u1/NetBSD/src/sys/arch/sparc/compile/GLUON sparc


>Description:
	If systat doesn't recognise the argument given on the command line
	it dumps core - the lookup() routine returns -1 on ambiguous & 0
	on not found but main() only checks for -1... so we get a 0 pointer
	dereference...

>How-To-Repeat:
	systat -coredumpplease
>Fix:
	The following (trivial :) patch makes main check for -1 & 0.

*** usr.bin/systat/main.c.orig	Wed Mar  8 10:10:41 1995
--- usr.bin/systat/main.c	Wed Mar  8 10:13:13 1995
***************
*** 92,98 ****
  			struct cmdtab *p;
  
  			p = lookup(&argv[0][1]);
! 			if (p == (struct cmdtab *)-1) {
  				fprintf(stderr, "%s: unknown request\n",
  				    &argv[0][1]);
  				exit(1);
--- 92,99 ----
  			struct cmdtab *p;
  
  			p = lookup(&argv[0][1]);
! 			if (p == (struct cmdtab *)-1 ||
! 						p == (struct cmdtab *)0) {
  				fprintf(stderr, "%s: unknown request\n",
  				    &argv[0][1]);
  				exit(1);
>Audit-Trail:
>Unformatted: