Bug 93469 - uninitialised struct stat in lpd prevents it from normal operation
Summary: uninitialised struct stat in lpd prevents it from normal operation
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: amd64 (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: Garance A Drosehn
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-17 09:30 UTC by Michael Szklarski
Modified: 2006-07-17 22:13 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Szklarski 2006-02-17 09:30:04 UTC
Already reported in:
http://www.freebsd.org/cgi/query-pr.cgi?pr=amd64/93413
now I have traced down the problem:

After first-time installation of spool directories, 
e.g. /var/spool/lpd/rattan , as seen in the Handbook, these directories are 
of course empty.

Running first time printout is successful, lpd creates "lock" file in the 
spool directory, but it has following (strange) attributes:

---xrwS--T  1 root  daemon  20 Feb 16 01:03 lock

Unfortunately, running printout for the next time does not work - lpr queues 
the job and nothing happens ! It is due to a sw-bug 
in /usr/src/usr.sbin/lpr/lpd/printjob.c, in function void printjob(struct 
printer* pp); i.e. look at the following lines of code:

[203]		 if (stat(pp->lock_file, &stb) == 0 && (stb.st_mode & LFM_PRINT_DIS))
		 		 		 exit(0);

Seems OK, but if NO LOCK FILE EXIST, "stb" remains uninitialized ! 
Unfortunately, this sets "+x" attribute, which is defined elsewhere
as
#define		 LFM_PRINT_DIS		 (S_IXUSR)
and it results in executing exit(0) in the line mentioned above, but only for 
the second time.

Further in the code one can find fchmod(lfd,stb.st_mode), which uses 
uninitialised "stb".

Fix: 

/usr/src/usr.sbin/lpr/lpd/printjob.c: function void printjob(struct printer* 
pp), line 203: replace those 2 lines mentioned above with:

		 if (stat(pp->lock_file, &stb) == 0)
		 {
		 		 if (stb.st_mode & LFM_PRINT_DIS)
		 		 {
		 		 		 exit(0);		 		 /* printing disabled */
		 		 }
		 } else
		 {
		 		 stb.st_mode = LOCK_FILE_MODE;
		 }

rebuild and install lpd. Works for me.

Workaround:

create lock files after creating spool directories:

 mkdir /var/spool/lpd/rattan
 touch /var/spool/lpd/rattan/lock

and/or change attributes of lock file:

 chmod 664 /var/spool/lpd/rattan/lock
How-To-Repeat: kill lpd.
remove spool directories.
recreate spool directories.
run lpd.
try to print twice (or more).
Comment 1 Tilman Keskinoz freebsd_committer freebsd_triage 2006-07-06 13:15:31 UTC
Responsible Changed
From-To: freebsd-amd64->gad

over to lpr maintainer
Comment 2 Garance A Drosehn freebsd_committer freebsd_triage 2006-07-06 20:22:58 UTC
I have a slightly different fix for this, which I have
been running with (here at RPI) for awhile now.  I
always wondered why no one else had noticed this
problem.  I guess it's just that when most people do
notice it, they just fix the permissions without ever
figuring out why the permissions were wrong to start
with.

Thanks for the report.

-- 
Garance Alistair Drosehn     =      gad@gilead.netel.rpi.edu
Senior Systems Programmer               or   gad@FreeBSD.org
Rensselaer Polytechnic Institute;             Troy, NY;  USA
Comment 3 Garance A Drosehn freebsd_committer freebsd_triage 2006-07-17 22:11:22 UTC
State Changed
From-To: open->closed

I have committed the change to lpd/printjob.c which should fix this 
problem.  The change had been in 7.x-current for a week without any 
apparent problems.