From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2197 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: Possible file stream bug Date: Wed, 24 Oct 2012 23:41:43 +0200 Message-ID: <20121024214143.GB24157@port70.net> References: <20121024205904.GJ254@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1351114917 15945 80.91.229.3 (24 Oct 2012 21:41:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 24 Oct 2012 21:41:57 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2198-gllmg-musl=m.gmane.org@lists.openwall.com Wed Oct 24 23:42:05 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1TR8iD-0003Ys-3U for gllmg-musl@plane.gmane.org; Wed, 24 Oct 2012 23:42:05 +0200 Original-Received: (qmail 11577 invoked by uid 550); 24 Oct 2012 21:41:57 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 11565 invoked from network); 24 Oct 2012 21:41:57 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:2197 Archived-At: * Paul Schutte [2012-10-24 23:22:13 +0200]: > It is not my code, but I can not see why it is invalid. beacuse the standard says so http://port70.net/~nsz/c/c99/n1256.html#7.19.3p4 and in annex j.2 in the undefined behaviour list there is: "- The value of a pointer to a FILE object is used after the associated file is closed" also note that the freopen spec says that it closes the underlying file so there is no reason for a separate fclose (or fflush) anyway http://port70.net/~nsz/c/c99/n1256.html#7.19.5.4p4 > Here is a strace when linked agains glibc: > > close(1) = 0 > open("/dev/tty", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 1 > fstat(1, {st_mode=S_IFCHR|0666, st_rdev=makedev(5, 0), ...}) = 0 > ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo > ...}) = 0 glibc clearly does not do close in freopen so it detects closed file streams and handles it in some way masking the error in the program