From owner-freebsd-bugs Tue Sep 19 12:24:58 1995 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id MAA25689 for bugs-outgoing; Tue, 19 Sep 1995 12:24:58 -0700 Received: from damian-hp.cisco.com (damian-hp.cisco.com [198.93.166.105]) by freefall.freebsd.org (8.6.12/8.6.6) with SMTP id MAA25683 for ; Tue, 19 Sep 1995 12:24:56 -0700 Message-Id: <199509191924.MAA25683@freefall.freebsd.org> Received: by damian-hp.cisco.com (1.38.193.4/16.2) id AA11959; Tue, 19 Sep 1995 12:31:29 -0700 From: Damian Ivereigh Subject: Two bug fixes to lpr system To: bugs@FreeBSD.org Date: Tue, 19 Sep 95 12:31:29 PDT Mailer: Elm [revision: 70.85] Sender: owner-bugs@FreeBSD.org Precedence: bulk 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 * * * *___________________________________________________________________________*