Subject: bin/155: mail leaves garbage NULs in files
To: None <gnats-admin>
From: Arne H}strek Juul <arnej@dsl.unit.no>
List: netbsd-bugs
Date: 03/05/1994 13:35:01
>Number:         155
>Category:       bin
>Synopsis:       Mail appended to mbox is preceded by NULs.
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    gnats-admin (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar  5 13:35:01 1994
>Originator:     Arne Juul
>Organization:
University of Trondheim, Norway
>Release:        
>Environment:
	NetBSD-current as of today
System: NetBSD skarven.dsl.unit.no 0.9a SKARVEN#1 i386


>Description:
	Messages read from mail are saved in mbox preceded by NULs.
	This is because of bogus use of ftruncate, effectively
	extending the file to the place where the messages should
	have ended, *then* appending the messages. May have been
	hidden by non-extending ftruncate or erronous append mode
	before.
>How-To-Repeat:
	With no special set-up (?), read mail and quit.
>Fix:
	Apply patch below, flushing stream before truncating.

*** def.h.orig	Fri Dec 17 08:13:38 1993
--- def.h	Sat Mar  5 22:13:19 1994
***************
*** 267,273 ****
   * useful just before closing an old file that was opened
   * for read/write.
   */
! #define trunc(stream)	ftruncate(fileno(stream), (long) ftell(stream))
  
  /*
   * Forward declarations of routine types to keep lint and cc happy.
--- 267,276 ----
   * useful just before closing an old file that was opened
   * for read/write.
   */
! #define trunc(stream)	do { \
! 		fflush(stream); \
! 		ftruncate(fileno(stream), (long) ftell(stream)) ; \
! 	} while (0)
  
  /*
   * Forward declarations of routine types to keep lint and cc happy.
>Audit-Trail:
>Unformatted:


------------------------------------------------------------------------------