Subject: bin/24205: tftp client does not remove interrupted file transfer
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <bdev@hss.hns.com>
List: netbsd-bugs
Date: 01/23/2004 12:45:19
>Number:         24205
>Category:       bin
>Synopsis:       tftp client does not remove interrupted file transfer
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 23 12:46:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Bashuman Deb
>Release:        1.6.1
>Organization:
Hughes Software System
>Environment:
NetBSD uxbuild 1.6.1 NetBSD 1.6.1 (MYKERN.KAME) #2: Tue Dec  2 14:13:05 JST 2003     root@uxbuild:/usr/src/kame/netbsd/sys/arch/i386/compile/MYKERN.KAME i386
>Description:
When a tftp file transfer for the tftp client is interrupted via ^C command the incomplete file does not get deleted. We find this slightly troublesome in and embedded environment since we would not want half downloaded files lying around, consuming all important space. 
>How-To-Repeat:
on the tftp prompt start a get and hit Ctrl+C in the middle of the transfer. The transfer stops but a half-downloaded file remains in the file system.
>Fix:
This is the fix to the problem. Change is in /usr/src/usr.bin/tftp/main.c


--- /usr/src/usr.bin/tftp/main.c	Sun Dec 31 03:00:18 2000
+++ main.c	Fri Jan 23 21:17:39 2004
@@ -84,6 +84,7 @@
 char	*margv[20];
 char	*prompt = "tftp";
 jmp_buf	toplevel;
+char downloading_file[LBUFLEN] = {0} ;
 
 void	get __P((int, char **));
 void	help __P((int, char **));
@@ -474,6 +475,7 @@
 		}
 		if (argc < 4) {
 			cp = argc == 3 ? argv[2] : tail(src);
+			strncpy(downloading_file,cp,LBUFLEN) ;
 			fd = creat(cp, 0644);
 			if (fd < 0) {
 				warn("%s", cp);
@@ -486,6 +488,9 @@
 			break;
 		}
 		cp = tail(src);         /* new .. jdg */
+		/* Copy out the name of the file which we were deleting
+		   */
+		strncpy(downloading_file,cp,LBUFLEN) ;
 		fd = creat(cp, 0644);
 		if (fd < 0) {
 			warn("%s", cp);
@@ -496,6 +501,8 @@
 				hostname, src, cp, mode);
 		recvfile(fd, src, mode);
 	}
+	/* Null out the downloading file */
+	downloading_file[0] = 0 ;
 }
 
 static void
@@ -584,6 +591,13 @@
 
 	signal(SIGALRM, SIG_IGN);
 	alarm(0);
+	/* Before we long jump out
+	   delete the downloading file
+	   */
+	if (downloading_file[0])
+	{
+		unlink(downloading_file) ;
+	}	
 	longjmp(toplevel, -1);
 }
 

>Release-Note:
>Audit-Trail:
>Unformatted: