Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Sep 95 12:31:29 PDT
From:      Damian Ivereigh <damian@cisco.com>
To:        bugs@FreeBSD.org
Subject:   Two bug fixes to lpr system
Message-ID:  <199509191924.MAA25683@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
Hi guys,

I have two bug fixes to the lpr code that I discovered when porting the
code to run on some other platforms, thought you might like them!

The first is to lpr/lpr.c :-
In the function test(), which is used to discover if a file can be printed
OK. If the -r option (remove files after printing) is used the function will
also check that the file can be removed. It uses the variable 'path' which
is declared as a char *, but space is never allocated to it. So the program
bombs when the strcpy is done. I have changed this to use a strdup() instead,
a free() comes later after it has been finished with. Here is the diff:-

*** save/lpr.c	Tue Sep 19 12:02:03 1995
--- lpr.c	Tue Sep 19 12:03:39 1995
***************
*** 600,608 ****
  			if (cp == file) {
  				fd = checkwriteperm(file,"/");
  			} else {
! 				strcpy(path,file);
  				*cp = '\0';
  				fd = checkwriteperm(path,file);
  				*cp = '/';
  			}
  			if (fd == 0)
--- 600,609 ----
  			if (cp == file) {
  				fd = checkwriteperm(file,"/");
  			} else {
! 				path=strdup(file);
  				*cp = '\0';
  				fd = checkwriteperm(path,file);
+ 				free(path);
  				*cp = '/';
  			}
  			if (fd == 0)


The second fix is to lpd/printjob.c:-
In the function printjob(), a check is made for whether the lock file
exists using stat(). If this fails (i.e. the lock does not exist) then
I presume the stat structure contains garbage, or is untouched. Further
down the code an fchmod call is done to update the perms on the lock
using a modified copy of the stat structure above. This works fine if
the lock exists, but if it did not the resulting mode on the lock file
is garbage - the mode on the lock file is important since it is how
printers are disabled or printing stopped. The fix is just to redo
a stat on the lock file before the fchmod(). Here is the diff:-

*** save/printjob.c	Tue Sep 19 12:02:03 1995
--- printjob.c	Tue Sep 19 12:04:17 1995
***************
*** 194,199 ****
--- 194,203 ----
  	}
  	if (nitems == 0)		/* no work to do */
  		exit(0);
+ 	if (fstat(lfd, &stb) < 0) {
+ 		syslog(LOG_ERR, "Lock has gone!: %s: %s: %m", printer, LO);
+ 		exit(1);
+ 	}
  	if (stb.st_mode & 01) {		/* reset queue flag */
  		if (fchmod(lfd, stb.st_mode & 0776) < 0)
  			syslog(LOG_ERR, "%s: %s: %m", printer, LO);


My thanks to all you guys working on the FreeBSD project. I run FreeBSD
at home and often use the source as a reference for my sysadmin work
at the office. This is my small contribution.

Hope these are of use to you.

Damian
--
_____________________________________________________________________________
* Damian Ivereigh        *                        * Cisco Systems, Inc.     *
* MIS Sys Admin          *      ||        ||      * 150 Tasman Dr.          *
* Unix System Admin      *    .||||.    .||||.    * San Jose, CA  95134     *
* Phone: 408-526-4413    * ..:||||||:..:||||||:.. *                         *
* Fax:   408-526-8220    *   cisco Systems, Inc.  * email:damian@cisco.com  *
* Toll Free 800-800-1180 *                        *                         *
*          Ext. 4413     *                        *                         *
*___________________________________________________________________________*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199509191924.MAA25683>