Subject: bin/17471: Bug in lprm options parsing; update usage
To: None <gnats-bugs@gnats.netbsd.org>
From: None <ginsbach@cray.com>
List: netbsd-bugs
Date: 07/03/2002 15:18:58
>Number:         17471
>Category:       bin
>Synopsis:       Bug in lprm options parsing; update usage
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 03 13:20:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Brian Ginsbach
>Release:        NetBSD 1.5.2, current
>Organization:
Cray Inc.
>Environment:
System: NetBSD nbtest.cray.com 1.5.2 NetBSD 1.5.2 (NBTEST) #1: Wed Feb 20 03:38:32 CST 2002 root@nbtest.cray.com:/usr/src/sys/arch/i386/compile/NBTEST i386


>Description:
	The error handling in the options parsing for lprm has a
	small bug.  When a negative wait time is given the error
	message has a "(null)" in place of the bad time.  The (null)
	should be the negative time from the command line.  The
	problem is that lprm does its own options parsing and does
	not use getopt(3).  The error message is passing optarg as
	the option string.  This is why the error message has the
	"(null)".

	The patch below also updates the usage message to reflect
	current reality.

>How-To-Repeat:
	# lprm -w -10
	lprm: wait time must be postive: (null)

>Fix:
Index: lprm.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/lpr/lprm/lprm.c,v
retrieving revision 1.10
diff -u -r1.10 lprm.c
--- lprm.c	1999/12/07 14:54:48	1.10
+++ lprm.c	2002/06/24 14:11:54
@@ -127,8 +127,8 @@
 					wait_time = atoi(*++argv);
 				}
 				if (wait_time < 0)
-					errx(1, "wait time must be postive: %s",
-					    optarg);
+					errx(1, "wait time must be postive: %d",
+					    wait_time);
 				if (wait_time < 30)
 				    warnx("warning: wait time less than 30 seconds");
 				break;
@@ -164,6 +164,7 @@
 static void
 usage()
 {
-	fprintf(stderr, "usage: lprm [-] [-Pprinter] [[job #] [user] ...]\n");
+	fprintf(stderr,
+		"usage: lprm [-] [-Pprinter] [-w maxwait] [[job #] [user] ...]\n");
 	exit(2);
 }
>Release-Note:
>Audit-Trail:
>Unformatted: