From Peter.Jeremy@alcatel-lucent.com  Tue Oct 19 00:54:44 2010
Return-Path: <Peter.Jeremy@alcatel-lucent.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 0381B106566B
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 19 Oct 2010 00:54:44 +0000 (UTC)
	(envelope-from Peter.Jeremy@alcatel-lucent.com)
Received: from ihemail3.lucent.com (ihemail3.lucent.com [135.245.0.37])
	by mx1.freebsd.org (Postfix) with ESMTP id C2D208FC08
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 19 Oct 2010 00:54:43 +0000 (UTC)
Received: from usnavsmail1.ndc.alcatel-lucent.com (usnavsmail1.ndc.alcatel-lucent.com [135.3.39.9])
	by ihemail3.lucent.com (8.13.8/IER-o) with ESMTP id o9J0c0Ir018237
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 18 Oct 2010 19:38:00 -0500 (CDT)
Received: from unixmail.au.alcatel-lucent.com (unixmail.au.alcatel-lucent.com [139.188.42.130])
	by usnavsmail1.ndc.alcatel-lucent.com (8.14.3/8.14.3/GMO) with ESMTP id o9J0btn4030480
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT)
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 18 Oct 2010 19:37:59 -0500
Received: from insmb.au.alcatel-lucent.com (insmb.au.alcatel-lucent.com [139.188.42.184])
	by unixmail.au.alcatel-lucent.com (8.13.8+Sun/8.13.3) with ESMTP id o9J0brlt020967
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 19 Oct 2010 11:37:53 +1100 (EST)
Received: from pjdesk.au.alcatel-lucent.com (pjdesk.au.alcatel-lucent.com [139.188.12.19])
	by insmb.au.alcatel-lucent.com (8.13.8+Sun/8.13.8) with ESMTP id o9J0UMop022566
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 19 Oct 2010 11:30:23 +1100 (EST)
Received: from pjdesk.au.alcatel-lucent.com (localhost [127.0.0.1])
	by pjdesk.au.alcatel-lucent.com (8.14.4/8.14.4) with ESMTP id o9J0UGRK049402;
	Tue, 19 Oct 2010 11:30:16 +1100 (EST)
	(envelope-from pjeremy@pjdesk.au.alcatel-lucent.com)
Received: (from pjeremy@localhost)
	by pjdesk.au.alcatel-lucent.com (8.14.4/8.14.4/Submit) id o9J0UGAt049401;
	Tue, 19 Oct 2010 11:30:16 +1100 (EST)
	(envelope-from pjeremy)
Message-Id: <201010190030.o9J0UGAt049401@pjdesk.au.alcatel-lucent.com>
Date: Tue, 19 Oct 2010 11:30:16 +1100 (EST)
From: Peter Jeremy <Peter.Jeremy@alcatel-lucent.com>
Reply-To: Peter Jeremy <Peter.Jeremy@alcatel-lucent.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] lp(1) fails on ZFS filesystem
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         151567
>Category:       bin
>Synopsis:       [patch] lp(1) fails on ZFS filesystem
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    edwin
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 19 01:00:24 UTC 2010
>Closed-Date:    Thu Oct 28 00:54:56 UTC 2010
>Last-Modified:  Thu Oct 28 01:00:17 UTC 2010
>Originator:     Peter Jeremy
>Release:        FreeBSD 8.1-PRERELEASE amd64
>Organization:
Alcatel-Lucent Australia
>Environment:
System: FreeBSD pjdesk.au.alcatel-lucent.com 8.1-PRERELEASE FreeBSD 8.1-PRERELEASE #19: Wed Jul 14 07:24:18 EST 2010 root@pjdesk.au.alcatel-lucent.com:/var/obj/usr/src/sys/pjdesk amd64

The code is identical in -current.

>Description:
	Printing from a ZFS filesystem using 'lp' fails and returns an
	email reporting "Your printer job was not printed because it was
	not linked to the original file".

	In order to protect against files being switched when files
	are printed using 'lp' or 'lpr -s', the st_dev and st_ino
	values for the original file are saved by lpr and verified
	by lpd before the file is printed.  Unfortunately, lpr prints
	both values using '%d' (although both fields are unsigned)
	and lpd(8) assumes a string of decimal digits.

	ZFS (at least) generates st_dev values greater than 2^31-1,
	resulting in negative values being printed - which lpd cannot
	parse, leading it to report that the file has been switched.

	A similar problem would occur with large inode numbers.

>How-To-Repeat:
	Find a file with either st_dev or st_ino greater than 2^31-1
	(stat(1) will report both numbers) and print it with 'lpq -s'.
	This should generate an email reporting that the file could
	not be printed because it was not linked to the original file

>Fix:
Index: lpr/lpr.c
===================================================================
RCS file: /usr/ncvs/src/usr.sbin/lpr/lpr/lpr.c,v
retrieving revision 1.44.32.1
diff -u -r1.44.32.1 lpr.c
--- lpr/lpr.c	3 Aug 2009 08:13:06 -0000	1.44.32.1
+++ lpr/lpr.c	19 Oct 2010 00:16:00 -0000
@@ -386,7 +386,7 @@
 			continue;	/* file unreasonable */
 
 		if (sflag && (cp = linked(arg)) != NULL) {
-			(void) snprintf(buf, sizeof(buf), "%d %d", statb.st_dev,
+			(void) snprintf(buf, sizeof(buf), "%u %u", statb.st_dev,
 				statb.st_ino);
 			card('S', buf);
 			if (format == 'p')
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: edwin 
State-Changed-When: Thu Oct 21 06:52:32 UTC 2010 
State-Changed-Why:  
Commited to head. 


Responsible-Changed-From-To: freebsd-bugs->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Thu Oct 21 06:52:32 UTC 2010 
Responsible-Changed-Why:  
Peter asked me to take care of this PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=151567 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/151567: commit references a PR
Date: Thu, 21 Oct 2010 06:52:19 +0000 (UTC)

 Author: edwin
 Date: Thu Oct 21 06:52:14 2010
 New Revision: 214124
 URL: http://svn.freebsd.org/changeset/base/214124
 
 Log:
   Fix printing of files located on ZFS filesystem with an st_dev or
   st_ino larger than 2**31.
   
   From the PR:
   
      Printing from a ZFS filesystem using 'lp' fails and returns an
      email reporting "Your printer job was not printed because it was
      not linked to the original file".
   
      In order to protect against files being switched when files
      are printed using 'lp' or 'lpr -s', the st_dev and st_ino
      values for the original file are saved by lpr and verified
      by lpd before the file is printed. Unfortunately, lpr prints
      both values using '%d' (although both fields are unsigned)
      and lpd(8) assumes a string of decimal digits.
   
      ZFS (at least) generates st_dev values greater than 2^31-1,
      resulting in negative values being printed - which lpd cannot
      parse, leading it to report that the file has been switched.
   
      A similar problem would occur with large inode numbers.
   
      How-To-Repeat:
   
      Find a file with either st_dev or st_ino greater than 2^31-1
      (stat(1) will report both numbers) and print it with 'lpq -s'.
      This should generate an email reporting that the file could
      not be printed because it was not linked to the original file
   
   PR:		bin/151567
   Submitted by:	Peter Jeremy <Peter.Jeremy@alcatel-lucent.com>
   MFC after:	1 week
 
 Modified:
   head/usr.sbin/lpr/lpr/lpr.c
 
 Modified: head/usr.sbin/lpr/lpr/lpr.c
 ==============================================================================
 --- head/usr.sbin/lpr/lpr/lpr.c	Thu Oct 21 01:13:41 2010	(r214123)
 +++ head/usr.sbin/lpr/lpr/lpr.c	Thu Oct 21 06:52:14 2010	(r214124)
 @@ -386,7 +386,7 @@ main(int argc, char *argv[])
  			continue;	/* file unreasonable */
  
  		if (sflag && (cp = linked(arg)) != NULL) {
 -			(void) snprintf(buf, sizeof(buf), "%d %d", statb.st_dev,
 +			(void) snprintf(buf, sizeof(buf), "%u %u", statb.st_dev,
  				statb.st_ino);
  			card('S', buf);
  			if (format == 'p')
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: edwin 
State-Changed-When: Thu Oct 28 00:54:40 UTC 2010 
State-Changed-Why:  
MFC into stable/8 done. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=151567 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/151567: commit references a PR
Date: Thu, 28 Oct 2010 00:54:23 +0000 (UTC)

 Author: edwin
 Date: Thu Oct 28 00:54:18 2010
 New Revision: 214442
 URL: http://svn.freebsd.org/changeset/base/214442
 
 Log:
   MFC of 214124
   
   Fix printing of files located on ZFS filesystem with an st_dev or
   st_ino larger than 2**31.
   
   From the PR:
   
      Printing from a ZFS filesystem using 'lp' fails and returns an
      email reporting "Your printer job was not printed because it was
      not linked to the original file".
   
      In order to protect against files being switched when files
      are printed using 'lp' or 'lpr -s', the st_dev and st_ino
      values for the original file are saved by lpr and verified
      by lpd before the file is printed. Unfortunately, lpr prints
      both values using '%d' (although both fields are unsigned)
      and lpd(8) assumes a string of decimal digits.
   
      ZFS (at least) generates st_dev values greater than 2^31-1,
      resulting in negative values being printed - which lpd cannot
      parse, leading it to report that the file has been switched.
   
      A similar problem would occur with large inode numbers.
   
      How-To-Repeat:
   
      Find a file with either st_dev or st_ino greater than 2^31-1
      (stat(1) will report both numbers) and print it with 'lpq -s'.
      This should generate an email reporting that the file could
      not be printed because it was not linked to the original file
   
   PR:           bin/151567
   Submitted by: Peter Jeremy <Peter.Jeremy@alcatel-lucent.com>
 
 Modified:
   stable/8/usr.sbin/lpr/lpr/lpr.c
 Directory Properties:
   stable/8/usr.sbin/lpr/   (props changed)
 
 Modified: stable/8/usr.sbin/lpr/lpr/lpr.c
 ==============================================================================
 --- stable/8/usr.sbin/lpr/lpr/lpr.c	Thu Oct 28 00:16:54 2010	(r214441)
 +++ stable/8/usr.sbin/lpr/lpr/lpr.c	Thu Oct 28 00:54:18 2010	(r214442)
 @@ -386,7 +386,7 @@ main(int argc, char *argv[])
  			continue;	/* file unreasonable */
  
  		if (sflag && (cp = linked(arg)) != NULL) {
 -			(void) snprintf(buf, sizeof(buf), "%d %d", statb.st_dev,
 +			(void) snprintf(buf, sizeof(buf), "%u %u", statb.st_dev,
  				statb.st_ino);
  			card('S', buf);
  			if (format == 'p')
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
