Truncate the file when opening it with write intent. Otherwise,

there's a good chance that garbage will remain at the end.

Closes PR # bin/2112: tftpd doesn't truncate ...

Reviewed by:	fenner
This commit is contained in:
Joerg Wunsch 1996-11-30 20:59:32 +00:00
parent 0c6ed4736c
commit 84e1b7d26b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=20052

View File

@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id$ * $Id: tftpd.c,v 1.4 1996/09/22 21:56:07 wosch Exp $
*/ */
#ifndef lint #ifndef lint
@ -435,7 +435,7 @@ validate_access(filep, mode)
return (err); return (err);
*filep = filename = pathname; *filep = filename = pathname;
} }
fd = open(filename, mode == RRQ ? 0 : 1); fd = open(filename, mode == RRQ ? O_RDONLY : O_WRONLY|O_TRUNC);
if (fd < 0) if (fd < 0)
return (errno + 100); return (errno + 100);
file = fdopen(fd, (mode == RRQ)? "r":"w"); file = fdopen(fd, (mode == RRQ)? "r":"w");