From lbnstn@lili23.lili.uni-bielefeld.de  Fri May  9 01:00:14 1997
Received: from lili23.lili.uni-bielefeld.de (lili23.lili.uni-bielefeld.de [129.70.23.23])
          by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id BAA19330
          for <FreeBSD-gnats-submit@freebsd.org>; Fri, 9 May 1997 01:00:09 -0700 (PDT)
Received: (from lbnstn@localhost)
	by lili23.lili.uni-bielefeld.de (8.8.5/8.8.5) id KAA00378;
	Fri, 9 May 1997 10:00:07 +0200 (CEST)
Message-Id: <199705090800.KAA00378@lili23.lili.uni-bielefeld.de>
Date: Fri, 9 May 1997 10:00:07 +0200 (CEST)
From: lbnstn@lili.uni-bielefeld.de
Reply-To: lbnstn@lili.uni-bielefeld.de
To: FreeBSD-gnats-submit@freebsd.org
Subject: Bug with -i option in /usr/bin/lpr
X-Send-Pr-Version: 3.2

>Number:         3556
>Category:       bin
>Synopsis:       Bug with -i option in /usr/bin/lpr
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    imp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri May  9 01:10:01 PDT 1997
>Closed-Date:    Wed Jan 6 01:26:11 MST 1999
>Last-Modified:  Wed Jan  6 01:26:53 MST 1999
>Originator:     Uwe Laubenstein
>Release:        FreeBSD 2.2.1-RELEASE i386
>Organization:
Universitaet Bielefeld, Germany
>Environment:

	

>Description:

There seems to be a bug in /usr/bin/lpr:
If lpr is invoked with -i but no argument to -i is supplied, then
then getopt eats up the argument following -i.
The bug is present in "FreeBSD 2.2-970422-RELENG" and "FreeBSD 2.2.1-RELEASE"

>How-To-Repeat:

	lpr -i /etc/motd		# hangs
	lpr -i -p /etc/motd		# ignores -p

>Fix:

*** /usr/src/usr.sbin/lpr/lpr/lpr.c.orig	Wed Feb 26 03:31:53 1997
--- /usr/src/usr.sbin/lpr/lpr/lpr.c	Thu May  8 12:08:12 1997
***************
*** 74,79 ****
--- 74,81 ----
  #include "lp.local.h"
  #include "pathnames.h"
  
+ extern int	optreset;
+ 
  static char	*cfname;	/* daemon control files, linked from tf's */
  static char	*class = host;	/* class title on header page */
  static char	*dfname;	/* data files */
***************
*** 121,127 ****
  	struct passwd *pw;
  	struct group *gptr;
  	register char *arg, *cp;
! 	char buf[BUFSIZ];
  	int c, i, f, errs;
  	struct stat stb;
  
--- 123,129 ----
  	struct passwd *pw;
  	struct group *gptr;
  	register char *arg, *cp;
! 	char *p, buf[BUFSIZ];
  	int c, i, f, errs;
  	struct stat stb;
  
***************
*** 198,204 ****
  
  		case 'i':		/* indent output */
  			iflag++;
! 			indent = atoi(optarg);
  			break;
  
  		case 'm':		/* send mail when done */
--- 200,214 ----
  
  		case 'i':		/* indent output */
  			iflag++;
! 			indent = strtol (optarg, &p, 10);
! 			/* if optarg is not a valid number we assume	*/
! 			/* it is another option or a filename		*/
! 			if (*p != '\0')
! 			{
! 				indent = 8;
! 				optreset = 1;
! 				optind--;
! 			}
  			break;
  
  		case 'm':		/* send mail when done */
>Release-Note:
>Audit-Trail:

From: j@uriah.heep.sax.de (J Wunsch)
To: lbnstn@lili.uni-bielefeld.de
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/3556: Bug with -i option in /usr/bin/lpr
Date: Fri, 9 May 1997 10:59:58 +0200

 As lbnstn@lili.uni-bielefeld.de wrote:
 
 > There seems to be a bug in /usr/bin/lpr:
 > If lpr is invoked with -i but no argument to -i is supplied, then
 > then getopt eats up the argument following -i.
 
 That's not a bug.  If there's something after -i, well, by definition,
 this _is_ the argument to -i.
 
 > --- 200,214 ----
 >   
 >   		case 'i':		/* indent output */
 >   			iflag++;
 > ! 			indent = strtol (optarg, &p, 10);
 > ! 			/* if optarg is not a valid number we assume	*/
 > ! 			/* it is another option or a filename		*/
 > ! 			if (*p != '\0')
 > ! 			{
 > ! 				indent = 8;
 > ! 				optreset = 1;
 > ! 				optind--;
 > ! 			}
 
 I agree that the validity of the argument should be checked, but lpr
 shouldn't make any assumptions but simply bail out with a usage error.
 Trying to be smart and `think' on behalf of the failing user is not
 TRT.
 
 -- 
 cheers, J"org
 
 joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
 Never trust an operating system you don't have sources for. ;-)

From: j@uriah.heep.sax.de (J Wunsch)
To: lbnstn@lili.uni-bielefeld.de
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/3556: Bug with -i option in /usr/bin/lpr
Date: Fri, 9 May 1997 10:59:58 +0200

 As lbnstn@lili.uni-bielefeld.de wrote:
 
 > There seems to be a bug in /usr/bin/lpr:
 > If lpr is invoked with -i but no argument to -i is supplied, then
 > then getopt eats up the argument following -i.
 
 That's not a bug.  If there's something after -i, well, by definition,
 this _is_ the argument to -i.
 
 > --- 200,214 ----
 >   
 >   		case 'i':		/* indent output */
 >   			iflag++;
 > ! 			indent = strtol (optarg, &p, 10);
 > ! 			/* if optarg is not a valid number we assume	*/
 > ! 			/* it is another option or a filename		*/
 > ! 			if (*p != '\0')
 > ! 			{
 > ! 				indent = 8;
 > ! 				optreset = 1;
 > ! 				optind--;
 > ! 			}
 
 I agree that the validity of the argument should be checked, but lpr
 shouldn't make any assumptions but simply bail out with a usage error.
 Trying to be smart and `think' on behalf of the failing user is not
 TRT.
 
 -- 
 cheers, J"org
 
 joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
 Never trust an operating system you don't have sources for. ;-)
Responsible-Changed-From-To: freebsd-bugs->imp 
Responsible-Changed-By: imp 
Responsible-Changed-When: Wed Sep 16 11:15:56 MDT 1998 
Responsible-Changed-Why:  
I've been tarred with the lpr tar baby before... 
State-Changed-From-To: open->closed 
State-Changed-By: imp 
State-Changed-When: Wed Jan 6 01:26:11 MST 1999 
State-Changed-Why:  
I've fixed this bug in a slightly different way than Uwe suggested, more 
along the lines that Joerge suggested. 
>Unformatted:
