From nobody  Thu Jan 23 07:04:41 1997
Received: (from nobody@localhost)
          by freefall.freebsd.org (8.8.5/8.8.5) id HAA22802;
          Thu, 23 Jan 1997 07:04:41 -0800 (PST)
Message-Id: <199701231504.HAA22802@freefall.freebsd.org>
Date: Thu, 23 Jan 1997 07:04:41 -0800 (PST)
From: staylor@cancercare.net
To: freebsd-gnats-submit@freebsd.org
Subject: tftpd.c does not truncate a file upon open (write)
X-Send-Pr-Version: www-1.0

>Number:         2566
>Category:       bin
>Synopsis:       tftpd.c does not truncate a file upon open (write)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 23 07:10:01 PST 1997
>Closed-Date:    Sat Jan 25 14:45:52 MET 1997
>Last-Modified:  Sat Jan 25 14:46:35 MET 1997
>Originator:     Steve Taylor
>Release:        2.1.5
>Organization:
Cancer Care Network, Inc.
>Environment:
FreeBSD cancer.cancercare.net 2.1.5-STABLE FreeBSD 2.1.5-STABLE #0: Wed Oct 16 0
2:06:19 CDT 1996     root@cancer.cancercare.net:/usr/src/sys/compile/CANCER  i38
6
>Description:
When TFTP-ing a file to the FreeBSD server, if a file already exists,
it is not truncated.  So, if the file that you are sending is shorter
than the file that's there already, the "new" file that you are sending
will end-up with some of the old file at the "new" file's end.
>How-To-Repeat:
Send a 50KB file via tftp.  Then, send a 20KB file.  Now, look at the
tftp-ed file on the FreeBSD machine - it's 50KB.  It contains 20KB of the
second file, followed by 30KB of the original (50KB) file.
>Fix:
change the following line in the /usr/src/libexec/tftpd/tftpd.c file:
  fd = open(filename, mode == RRQ ? 0 : 1)
     to
fd = open(filename, mode == RRQ ? 0 : 1 | O_TRUNC)

And, while you are at it, you may want to consider using O_RDONLY and
O_WRONLY instead of 0 and 1.
>Release-Note:
>Audit-Trail:

From: j@uriah.heep.sax.de (J Wunsch)
To: staylor@cancercare.net
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/2566: tftpd.c does not truncate a file upon open (write)
Date: Thu, 23 Jan 1997 21:10:31 +0100

 As staylor@cancercare.net wrote:
 
 > When TFTP-ing a file to the FreeBSD server, if a file already exists,
 > it is not truncated.
 
 Already fixed by rev 1.5 of tftpd.c (it's in -current and 2.2).
 
 -- 
 cheers, J"org
 
 joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
 Never trust an operating system you don't have sources for. ;-)
State-Changed-From-To: open->closed 
State-Changed-By: joerg 
State-Changed-When: Sat Jan 25 14:45:52 MET 1997 
State-Changed-Why:  
Already fixed by time of submission. 

>Unformatted:
