Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Sun, 17 Jun 2012 17:25:18 -0400
From: Rich Felker <dalias@...ifal.cx>
To: musl@...ts.openwall.com
Subject: Re: setvbuf, __fbufsize bug

On Sun, Jun 17, 2012 at 11:07:33PM +0200, Szabolcs Nagy wrote:
> * Bruno Haible <bruno@...sp.org> [2012-06-17 21:26:44 +0200]:
> > With musl-0.9.1: This program shows that after calling setvbuf to make
> > a stream buffered, it may in fact be unbuffered (__fbufsize returns 0).
> > 
> 
> this is a broken test in gnulib
> see c99 7.19.5.6:
> 
> "The setvbuf function may be used only after the stream pointed to by
> stream has been associated with an open file and before any other operation
> (other than an unsuccessful call to setvbuf) is performed on the stream."

Indeed, the test is invoking undefined behavior. musl's setvbuf does
not support any usage but turning off buffering (or switching from
full to line buffering) on a stream that initially had buffering. The
only situation where it's even possible to use setvbuf for another
purpose without invoking UB is to add buffering to stderr (which is
originally unbuffered) or to switch to a larger caller-provided buffer
(which is rarely useful and is the sort of backwards
micro-optimization applications should not be doing these days). If
anyone thinks this usage is sufficiently important that we should
support these uses, please explain why.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.