From ipfw@ya3.so-net.ne.jp  Sun Mar 11 04:11:50 2001
Return-Path: <ipfw@ya3.so-net.ne.jp>
Received: from mgate04.so-net.ne.jp (mgate04.so-net.ne.jp [210.139.254.151])
	by hub.freebsd.org (Postfix) with ESMTP id 45FB137B719
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 11 Mar 2001 04:11:49 -0800 (PST)
	(envelope-from ipfw@ya3.so-net.ne.jp)
Received: from mail.ya3.so-net.ne.jp (mspool11.so-net.ne.jp [210.139.248.11])
	by mgate04.so-net.ne.jp (8.8.8+3.0Wbeta9/3.6W01022711) with ESMTP id VAA10588
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 11 Mar 2001 21:11:48 +0900 (JST)
Received: from localhost (p78a12f.kngwnt01.ap.so-net.ne.jp [61.120.161.47])
	by mail.ya3.so-net.ne.jp (8.9.3/3.7W01022316) with ESMTP id VAA01771
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 11 Mar 2001 21:11:47 +0900 (JST)
Message-Id: <20010311211810J.ipfw@ya3.so-net.ne.jp>
Date: Sun, 11 Mar 2001 21:18:10 +0900
From: Yoshihiro Koya <Yoshihiro.Koya@math.yokohama-cu.ac.jp>
Sender: ipfw <ipfw@ya3.so-net.ne.jp>
To: FreeBSD-gnats-submit@freebsd.org
Subject: ftpd doesn't count transfered data bytes
X-Send-Pr-Version: 3.113

>Number:         25699
>Category:       bin
>Synopsis:       ftpd bug
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    des
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Mar 11 04:20:01 PST 2001
>Closed-Date:    Sun Apr 29 03:54:47 PDT 2001
>Last-Modified:  Sun Apr 29 03:55:24 PDT 2001
>Originator:     Yoshihiro Koya
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Dept. of Math. Sci., Yokohama City University
>Environment:
System: FreeBSD current.my.domain 5.0-CURRENT FreeBSD 5.0-CURRENT #1: Sat Mar 10 15:25:02 JST 2001 root@current.my.domain:/usr/obj/usr/src/sys/current i386

The same bug can be found on 4.3-BETA maybe.
>Description:
	/usr/libexec/ftpd doesn't count the total bytes amount of
	a file sent.

	I obtain syslog as follows:

Mar 11 16:22:25 current ftpd[964]: FTP LOGIN FROM localhost as someuser
Mar 11 16:22:42 current ftpd[964]: get /home/someuser/send-pr.0305 = 0 bytes
Mar 11 19:43:25 current ftpd[2253]: connection from localhost (192.168.0.11)
Mar 11 19:43:28 current ftpd[2253]: FTP LOGIN FROM localhost as someuser
Mar 11 19:43:41 current ftpd[2253]: get /home/someuser/send-pr.0305 = 0 bytes
Mar 11 19:44:13 current ftpd[2305]: connection from localhost (192.168.0.11)
Mar 11 19:44:18 current ftpd[2305]: FTP LOGIN FROM localhost as someuser
Mar 11 19:44:39 current ftpd[2305]: get /home/someuser/src/perl-current.tar.gz = 0 bytes

  I always get the 0 byte file via ftp. But, the file size isn't
  zero byte, of course.
>How-To-Repeat:
	Confirm that ftpd can record log.
	Check /etc/inetd.conf and /etc/syslog.conf.
	 
	% ftp localhost

	Get some files, and check the logfile recorded by ftpd.
>Fix:
--- /usr/src/libexec/ftpd/ftpd.c.orig	Sun Mar 11 20:19:53 2001
+++ /usr/src/libexec/ftpd/ftpd.c	Sun Mar 11 20:46:15 2001
@@ -1756,10 +1756,12 @@
 					if (!cnt)
 						goto oldway;
 
+					byte_count = offset;
 					goto data_err;
 				}
 			}
 
+			byte_count = offset;
 			reply(226, "Transfer complete.");
 			return;
 		}
>Release-Note:
>Audit-Trail:

From: Dag-Erling Smorgrav <des@ofug.org>
To: Yoshihiro Koya <Yoshihiro.Koya@math.yokohama-cu.ac.jp>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/25699: ftpd doesn't count transfered data bytes
Date: 11 Mar 2001 14:19:23 +0100

 Yoshihiro Koya <Yoshihiro.Koya@math.yokohama-cu.ac.jp> writes:
 > >Fix:
 > --- /usr/src/libexec/ftpd/ftpd.c.orig	Sun Mar 11 20:19:53 2001
 > +++ /usr/src/libexec/ftpd/ftpd.c	Sun Mar 11 20:46:15 2001
 > @@ -1756,10 +1756,12 @@
 >  					if (!cnt)
 >  						goto oldway;
 >  
 > +					byte_count = offset;
 >  					goto data_err;
 >  				}
 >  			}
 >  
 > +			byte_count = offset;
 >  			reply(226, "Transfer complete.");
 >  			return;
 >  		}
 
 Wrong patch. You set byte_count to offset, so if the transfer was
 restarted in mid-file you also count bytes that *weren't* transferred.
 The correct fix is:
 
 Index: ftpd.c
 ===================================================================
 RCS file: /home/ncvs/src/libexec/ftpd/ftpd.c,v
 retrieving revision 1.72
 diff -u -r1.72 ftpd.c
 --- ftpd.c      2000/12/20 03:34:54     1.72
 +++ ftpd.c      2001/03/11 13:16:57
 @@ -1749,6 +1749,7 @@
                         while (err != -1 && cnt < filesize) {
                                 err = sendfile(filefd, netfd, offset, len,
                                         (struct sf_hdtr *) NULL, &cnt, 0);
 +                               byte_count += cnt;
                                 offset += cnt;
                                 len -= cnt;
 
 
 (apply with 'patch -l' due to cut&paste corruption)
 
 DES
 -- 
 Dag-Erling Smorgrav - des@ofug.org
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: dd 
Responsible-Changed-When: Sat Apr 28 20:27:52 PDT 2001 
Responsible-Changed-Why:  
Better patch submitted by des.  Perhaps he should commit it (if this didn't 
already happen)? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=25699 
State-Changed-From-To: open->closed 
State-Changed-By: des 
State-Changed-When: Sun Apr 29 03:54:47 PDT 2001 
State-Changed-Why:  
Fixed & MFCed before 4.3-RELEASE. 

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