Subject: bin/3160: ftp dumps core if you try to get a zero length file (obsolets bin/3157)
To: None <gnats-bugs@gnats.netbsd.org>
From: None <frueauf@ira.uka.de>
List: netbsd-bugs
Date: 01/29/1997 21:00:23
>Number:         3160
>Category:       bin
>Synopsis:       ftp dumps core if you try to get a zero length file (obsolets bin/3157)
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jan 29 12:20:01 1997
>Last-Modified:
>Originator:     Thorsten Frueauf
>Organization:
private
	
>Release:        <NetBSD-current source date> NetBSD current 28.01.1997
>Environment:
	
System: NetBSD cyberlap 1.2B NetBSD 1.2B (CYBERLAP) #3: Tue Jan 28 11:11:47 CET 1997 frueauf@cyberlap:/usr/src/sys/arch/i386/compile/CYBERLAP i386


>Description:
	
If you try to get a zero length file with ftp, it dumps core with a 
Floating exception.

>How-To-Repeat:
	
Try the following:
on host A: `toch crash` # make a zero length file
on host B: `ftp hostA`
           get crash

and watch:
ftp> dir crash
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
-rw-------  1 frueauf  gr41            0 Jan 29 13:29 crash
226 Transfer complete.
ftp> get crash
local: crash remote: crash
200 PORT command successful.
150 Opening BINARY mode data connection for crash (0 bytes).
Floating exception (core dumped)

-rw-------  1 frueauf  gr41  483700 Jan 29 13:30 ftp.core
Core was generated by `ftp'.
Program terminated with signal 8, Floating point exception.
Reading symbols from /usr/libexec/ld.so...done.
Reading symbols from /usr/lib/libedit.so.0.0...done.
Reading symbols from /usr/lib/libtermcap.so.0.0...done.
Reading symbols from /usr/lib/libc.so.12.10...done.
#0  0x1007ab65 in __qdivrem ()
(gdb) bt
#0  0x1007ab65 in __qdivrem ()
#1  0x10078914 in __divdi3 ()
#2  0xc6f0 in progressmeter (flag=-1) at /src/usr.bin/ftp/util.c:421
#3  0x8820 in recvrequest (cmd=0x2261 "RETR", local=0x1d0d0 "crash", 
    remote=0x181b8 "crash", lmode=0x21fb "w", printnames=1)
    at /src/usr.bin/ftp/ftp.c:929
#4  0x24cb in getit (argc=3, argv=0x1e000, restartit=0, mode=0x21fb "w")
    at /src/usr.bin/ftp/cmds.c:523
#5  0x222f in get (argc=2, argv=0x1e000) at /src/usr.bin/ftp/cmds.c:441
#6  0xaa4c in cmdscanner (top=1) at /src/usr.bin/ftp/main.c:357
#7  0xa696 in main (argc=1, argv=0xf7bfd834) at /src/usr.bin/ftp/main.c:221

>Fix:
	
Apply the following patch to /src/usr.bin/ftp/util.c:

*** util.c	Tue Jan 21 10:10:07 1997
--- util.c-milano	Wed Jan 29 20:51:06 1997
***************
*** 402,408 ****
  
  	if (flag < 0)
  		(void) gettimeofday(&start, (struct timezone *)0);
! 	if (!progress || filesize < 0)
  		return;
  	if (flag < 0) {
  		before.tv_sec = -1;
--- 402,408 ----
  
  	if (flag < 0)
  		(void) gettimeofday(&start, (struct timezone *)0);
! 	if (!progress || filesize <= 0)
  		return;
  	if (flag < 0) {
  		before.tv_sec = -1;
>Audit-Trail:
>Unformatted:
ftp dumps core if you try to get a zero length file (obsolets bin/3157)