Bug 25699

Summary: ftpd bug
Product: Base System Reporter: Yoshihiro Koya <Yoshihiro.Koya>
Component: binAssignee: Dag-Erling Smørgrav <des>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 5.0-CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Yoshihiro Koya 2001-03-11 12:20:01 UTC
	/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.
Comment 1 des 2001-03-11 13:19:23 UTC
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
Comment 2 dd freebsd_committer freebsd_triage 2001-04-29 04:27:52 UTC
Responsible Changed
From-To: freebsd-bugs->des

Better patch submitted by des.  Perhaps he should commit it (if this didn't 
already happen)?
Comment 3 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2001-04-29 11:54:47 UTC
State Changed
From-To: open->closed

Fixed & MFCed before 4.3-RELEASE.