From nobody@FreeBSD.org  Fri Oct  6 04:51:35 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 24A9F16A403
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  6 Oct 2006 04:51:35 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id E5A3D43D45
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  6 Oct 2006 04:51:34 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k964pYLp004622
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 6 Oct 2006 04:51:34 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k964pYEM004621;
	Fri, 6 Oct 2006 04:51:34 GMT
	(envelope-from nobody)
Message-Id: <200610060451.k964pYEM004621@www.freebsd.org>
Date: Fri, 6 Oct 2006 04:51:34 GMT
From: Geoffrey Giesemann <geoffwa@cs.rmit.edu.au>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] cp's SIGINFO handler percent complete status wraps around when the bytes copied exceeds size_t
X-Send-Pr-Version: www-2.3

>Number:         104039
>Category:       bin
>Synopsis:       [patch] cp's SIGINFO handler percent complete status wraps around when the bytes copied exceeds size_t
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Oct 06 05:00:38 GMT 2006
>Closed-Date:    Sat Oct 21 16:03:17 GMT 2006
>Last-Modified:  Sat Oct 21 16:03:17 GMT 2006
>Originator:     Geoffrey Giesemann
>Release:        6.2-PRERELEASE
>Organization:
>Environment:
FreeBSD geoff.cs.rmit.edu.au 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #10: Thu Oct  5 14:44:56 EST 2006     root@geoff.cs.rmit.edu.au:/usr/obj/usr/src/sys/GEOFF  i386
>Description:
cp keeps a running total of the bytes copied, so that when it gets a SIGINFO it can print a percentage copied.

The variable is of type size_t, so when bytes copied exceeds 4GB, it wraps to a negative value. Changing the type to off_t fixes this.
>How-To-Repeat:
dd if=/dev/zero of=/somewhere/with/lotsa/space/file bs=512 count=10M
cp /somewhere/with/lotsa/space/file /somewhere/with/lotsa/space/file2
<hammer ^T>
>Fix:
Change type of wtotal to off_t:

--- /usr/src/bin/cp/utils_old.c Fri Oct  6 14:05:34 2006
+++ /usr/src/bin/cp/utils.c     Fri Oct  6 14:25:19 2006
@@ -64,7 +64,7 @@
        int ch, checkch, from_fd = 0, rcount, rval, to_fd = 0;
        ssize_t wcount;
        size_t wresid;
-       size_t wtotal;
+       off_t wtotal;
        char *bufp;
 #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
        char *p;

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: maxim 
State-Changed-When: Fri Oct 6 08:30:49 UTC 2006 
State-Changed-Why:  
Fixed in HEAD.  Thanks! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/104039: commit references a PR
Date: Fri,  6 Oct 2006 08:31:07 +0000 (UTC)

 maxim       2006-10-06 08:30:33 UTC
 
   FreeBSD src repository
 
   Modified files:
     bin/cp               utils.c 
   Log:
   o Hold copied bytes counter in off_t.  This prevents statistics
   displayed by SIGINFO handler from overflow.
   
   PR:             bin/104039
   Submitted by:   Geoffrey Giesemann
   MFC after:      2 weeks
   
   Revision  Changes    Path
   1.50      +1 -1      src/bin/cp/utils.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: maxim 
State-Changed-When: Sat Oct 21 16:02:58 UTC 2006 
State-Changed-Why:  
Merged to RELENG_6. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=104039 
>Unformatted:
