Subject: bin/5315: sh getopts prints error messages to stdout
To: None <gnats-bugs@gnats.netbsd.org>
From: Dan Winship <danw@mit.edu>
List: netbsd-bugs
Date: 04/18/1998 13:58:57
>Number: 5315
>Category: bin
>Synopsis: sh getopts prints error messages to stdout
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Apr 18 11:05:00 1998
>Last-Modified:
>Originator: Dan Winship
>Organization:
MIT
>Release: current
>Environment:
System: NetBSD zork.mit.edu 1.3E NetBSD 1.3E (COCONUT) #8: Wed Mar 25 00:31:37 EST 1998 danw@zork.mit.edu:/usr/src/sys/arch/i386/compile/COCONUT i386
>Description:
If you pass a bad option to a /bin/sh script that uses getopts,
it will print "Illegal option -x" to stdout instead of stderr.
>How-To-Repeat:
/usr/bin/lp -x 2> /dev/null
>Fix:
*** options.c.orig Sat Apr 18 13:37:44 1998
--- options.c Sat Apr 18 13:39:14 1998
***************
*** 441,447 ****
err |= setvarsafe("OPTARG", s, 0);
}
else {
! out1fmt("Illegal option -%c\n", c);
(void) unsetvar("OPTARG");
}
c = '?';
--- 441,447 ----
err |= setvarsafe("OPTARG", s, 0);
}
else {
! outfmt(out2, "Illegal option -%c\n", c);
(void) unsetvar("OPTARG");
}
c = '?';
***************
*** 460,466 ****
c = ':';
}
else {
! out1fmt("No arg for -%c option\n", c);
(void) unsetvar("OPTARG");
c = '?';
}
--- 460,466 ----
c = ':';
}
else {
! outfmt(out2, "No arg for -%c option\n", c);
(void) unsetvar("OPTARG");
c = '?';
}
>Audit-Trail:
>Unformatted: