From nobody@FreeBSD.org  Tue Jan 29 07:37:51 2002
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id E7AE337B400
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 29 Jan 2002 07:37:50 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.6/8.11.6) id g0TFbol82304;
	Tue, 29 Jan 2002 07:37:50 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200201291537.g0TFbol82304@freefall.freebsd.org>
Date: Tue, 29 Jan 2002 07:37:50 -0800 (PST)
From: Todd Hayton <thayton@torrentnet.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: tftp will still try and receive traffic even after receiver's disk has filled
X-Send-Pr-Version: www-1.0

>Number:         34412
>Category:       bin
>Synopsis:       [patch] tftp(1) will still try and receive traffic even after receiver's disk has filled
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 29 07:40:01 PST 2002
>Closed-Date:    
>Last-Modified:  Thu Feb 14 10:29:10 UTC 2008
>Originator:     Todd Hayton
>Release:        FreeBSD 2.2
>Organization:
Ericsson
>Environment:
>Description:
When copying a large file using tftp, if during the course of the
transfer the disk of the receiver fills up, tftp will still try
and receive more data from the sender ignoring the fact that the
write()'s are failing because there is no more space left.

Glancing over the tftp code (/usr/src/usr.bin/tftp) I noticed that
the function recvfile() in tftp.c is responsible for the reception 
of a file. Within this function another function called write_behind() 
is responsible for writing the received data to disk. Although the
write_behind() function returns the return value of the write() system 
call, this return value is never checked in the calling function recvfile().

The result is that tftp will continue recv'ing and subsequently
trying to write() the data despite the fact that each call to write()
fails.
>How-To-Repeat:
Try tftp'ing a large file onto a filesystem that doesn't have enough
room to hold it.
>Fix:
      
>Release-Note:
>Audit-Trail:

From: Maxim Konovalov <maxim@macomnet.ru>
To: Todd Hayton <thayton@torrentnet.com>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: misc/34412: tftp will still try and receive traffic even after
 receiver's disk has filled
Date: Tue, 29 Jan 2002 20:00:02 +0300 (MSK)

 Here is untested patch for -current (applied for RELENG_2_2_0_RELEASE
 too):
 
 Index: tftpd.c
 ===================================================================
 RCS file: /home/ncvs/src/libexec/tftpd/tftpd.c,v
 retrieving revision 1.21
 diff -u -r1.21 tftpd.c
 --- tftpd.c	2001/11/22 05:08:35	1.21
 +++ tftpd.c	2002/01/29 16:51:15
 @@ -652,7 +652,12 @@
  			syslog(LOG_ERR, "write: %m");
  			goto abort;
  		}
 +		errno = 0;
  		write_behind(file, pf->f_convert);
 +		if (errno == ENOSPC) {
 +			nak(ENOSPACE);
 +			goto abort;
 +		}
  		for ( ; ; ) {
  			alarm(rexmtval);
  			n = recv(peer, dp, PKTSIZE, 0);
 @@ -683,7 +688,12 @@
  			goto abort;
  		}
  	} while (size == SEGSIZE);
 +	errno = 0;
  	write_behind(file, pf->f_convert);
 +	if (errno == ENOSPC) {
 +		nak(ENOSPACE);
 +		goto abort;
 +	}
  	(void) fclose(file);            /* close data file */
 
  	ap->th_opcode = htons((u_short)ACK);    /* send the "final" ack */
 
 -- 
 Maxim Konovalov, MAcomnet, Internet-Intranet Dept., system engineer
 phone: +7 (095) 796-9079, mailto: maxim@macomnet.ru
 

From: Maxim Konovalov <maxim@macomnet.ru>
To: Todd Hayton <thayton@torrentnet.com>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: misc/34412: tftp will still try and receive traffic even after
 receiver's disk has filled
Date: Tue, 29 Jan 2002 21:16:16 +0300 (MSK)

 ... and for tftp:
 
 Index: tftp.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/tftp/tftp.c,v
 retrieving revision 1.7
 diff -u -r1.7 tftp.c
 --- tftp.c	2001/12/11 23:43:15	1.7
 +++ tftp.c	2002/01/29 18:13:09
 @@ -242,6 +242,10 @@
  			goto abort;
  		}
  		write_behind(file, convert);
 +		if (errno == ENOSPC ) {
 +			nak(errno + 100);
 +			break;
 +		}
  		for ( ; ; ) {
  			alarm(rexmtval);
  			do  {
 
 -- 
 Maxim Konovalov, MAcomnet, Internet-Intranet Dept., system engineer
 phone: +7 (095) 796-9079, mailto: maxim@macomnet.ru
 

From: "Crist J. Clark" <cjc@FreeBSD.ORG>
To: Maxim Konovalov <maxim@macomnet.ru>
Cc: bug-followup@FreeBSD.ORG
Subject: Re: misc/34412: tftp will still try and receive traffic even after receiver's disk has filled
Date: Tue, 29 Jan 2002 14:50:17 -0800

 On Tue, Jan 29, 2002 at 10:20:02AM -0800, Maxim Konovalov wrote:
 [snip]
 
 >  ... and for tftp:
 >  
 >  Index: tftp.c
 >  ===================================================================
 >  RCS file: /home/ncvs/src/usr.bin/tftp/tftp.c,v
 >  retrieving revision 1.7
 >  diff -u -r1.7 tftp.c
 >  --- tftp.c	2001/12/11 23:43:15	1.7
 >  +++ tftp.c	2002/01/29 18:13:09
 >  @@ -242,6 +242,10 @@
 >   			goto abort;
 >   		}
 >   		write_behind(file, convert);
 >  +		if (errno == ENOSPC ) {
 >  +			nak(errno + 100);
 >  +			break;
 >  +		}
 >   		for ( ; ; ) {
 >   			alarm(rexmtval);
 >   			do  {
 
 Actually, this should read,
 
 Index: tftp.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/tftp/tftp.c,v
 retrieving revision 1.7
 diff -u -r1.7 tftp.c
 --- tftp.c	2001/12/11 23:43:15	1.7
 +++ tftp.c	2002/01/29 18:13:09
 @@ -242,6 +242,10 @@
  			goto abort;
  		}
  		write_behind(file, convert);
 +		if (errno == ENOSPC ) {
 +			nak(ENOSPACE);
 +			break;
 +		}
  		for ( ; ; ) {
  			alarm(rexmtval);
  			do  {
 
 That is, there is a specific error code for this condition specified
 within the TFTP protocol (RFC 1350).
 -- 
 Crist J. Clark                     |     cjclark@alum.mit.edu
                                    |     cjclark@jhu.edu
 http://people.freebsd.org/~cjc/    |     cjc@freebsd.org
State-Changed-From-To: open->feedback 
State-Changed-By: sheldonh 
State-Changed-When: Wed Jan 30 04:32:46 PST 2002 
State-Changed-Why:  
Waiting for the originator to try Maxim's tftpd patch and Crist's 
tftp patch. 

Please copy your feedback to <bug-followup@freebsd.org>, using the 
subject line of this message. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=34412 
State-Changed-From-To: feedback->closed 
State-Changed-By: ceri 
State-Changed-When: Sun Jun 8 11:02:38 PDT 2003 
State-Changed-Why:  
Feedback timeout (6 months or more). 
I will handle any feedback that this closure generates. 


Responsible-Changed-From-To: freebsd-bugs->ceri 
Responsible-Changed-By: ceri 
Responsible-Changed-When: Sun Jun 8 11:02:38 PDT 2003 
Responsible-Changed-Why:  
Feedback timeout (6 months or more). 
I will handle any feedback that this closure generates. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=34412 
State-Changed-From-To: closed->open 
State-Changed-By: maxim 
State-Changed-When: Sun Jun 8 11:38:37 PDT 2003 
State-Changed-Why:  
It is still an issue. 


Responsible-Changed-From-To: ceri->maxim 
Responsible-Changed-By: maxim 
Responsible-Changed-When: Sun Jun 8 11:38:37 PDT 2003 
Responsible-Changed-Why:  
Hope I will commit a fix soon. 

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

From: "Jason A. Young" <jyoung@power.doogles.com>
To: freebsd-gnats-submit@freebsd.org, <thayton@torrentnet.com>
Cc:  
Subject: Re: misc/34412: tftp will still try and receive traffic even after
 receiver disk has filled
Date: Wed, 3 Sep 2003 01:56:12 -0500 (CDT)

 I modified Crist's and Maxim's patches slightly to improve error
 reporting, and to compile for CURRENT. Light testing of out-of-space
 conditions on both the client and server side succeeded.
 
 *** tftp.c.orig Tue Sep  2 20:02:18 2003
 --- tftp.c      Tue Sep  2 20:08:53 2003
 ***************
 *** 261,270 ****
 --- 261,275 ----
                         alarm(0);
                         warn("sendto");
                         goto abort;
                 }
                 write_behind(file, convert);
 +               if (errno == ENOSPC ) {
 +                       nak(ENOSPACE, (struct sockaddr *)&peer);
 +                       printf("Transfer aborted (out of space)\n");
 +                       break;
 +               }
                 for ( ; ; ) {
                         alarm(rexmtval);
                         do  {
                                 fromlen = sizeof(from);
                                 n = recvfrom(f, dp, PKTSIZE, 0,
 
 *** tftpd.c.orig        Tue Sep  2 20:11:48 2003
 --- tftpd.c     Tue Sep  2 20:38:20 2003
 ***************
 *** 680,690 ****
 --- 680,696 ----
   send_ack:
                 if (send(peer, ackbuf, 4, 0) != 4) {
                         syslog(LOG_ERR, "write: %m");
                         goto abort;
                 }
 +               errno = 0;
                 write_behind(file, pf->f_convert);
 +               if (errno == ENOSPC) {
 +                       nak(ENOSPACE);
 +                       syslog(LOG_ERR, "write_behind: %m");
 +                       goto abort;
 +               }
                 for ( ; ; ) {
                         alarm(rexmtval);
                         n = recv(peer, dp, PKTSIZE, 0);
                         alarm(0);
                         if (n < 0) {            /* really? */
 
 
 -- 
 Jason Young, CCIE #8607, MCSE
 Sr. Network Technician, WAN Technologies
 (314)817-0131
 http://www.wantec.com
 

From: Maxim Konovalov <maxim@macomnet.ru>
To: "Jason A. Young" <jyoung@power.doogles.com>
Cc: bug-followup@freebsd.org
Subject: Re: misc/34412: tftp will still try and receive traffic even after
 receiver disk has filled
Date: Wed, 3 Sep 2003 11:46:22 +0400 (MSD)

 Hi Jason,
 
 On Wed, 3 Sep 2003, 00:00-0700, Jason A. Young wrote:
 
 > The following reply was made to PR misc/34412; it has been noted by GNATS.
 >
 > From: "Jason A. Young" <jyoung@power.doogles.com>
 > To: freebsd-gnats-submit@freebsd.org, <thayton@torrentnet.com>
 > Cc:
 > Subject: Re: misc/34412: tftp will still try and receive traffic even after
 >  receiver disk has filled
 > Date: Wed, 3 Sep 2003 01:56:12 -0500 (CDT)
 >
 >  I modified Crist's and Maxim's patches slightly to improve error
 >  reporting, and to compile for CURRENT. Light testing of out-of-space
 >  conditions on both the client and server side succeeded.
 
 I do not think it is a correct solution for the problem.  It is a
 workaround but a more correct solution is adding an error check to
 write_behind() and writeit().  See a comment at the top of
 tftp/tftpsubs.c.  Thanks for the effort anyway.
 
 -- 
 Maxim Konovalov, maxim@macomnet.ru, maxim@FreeBSD.org
Responsible-Changed-From-To: maxim->freebsd-bugs 
Responsible-Changed-By: maxim 
Responsible-Changed-When: Fri Apr 9 10:48:02 PDT 2004 
Responsible-Changed-Why:  
Be honest - I do not have a free time to work on this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=34412 
Responsible-Changed-From-To: freebsd-bugs->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Oct 8 08:23:12 UTC 2007 
Responsible-Changed-Why:  
I'm interested in this patch. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=34412 
Responsible-Changed-From-To: edwin->freebsd-bugs 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Thu Feb 14 10:27:36 UTC 2008 
Responsible-Changed-Why:  
Give back into the pool until later. 

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