Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 28 May 2015 23:05:16 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: stdio fixes & internals documentation

On Thu, May 28, 2015 at 09:39:37PM -0400, Rich Felker wrote:
> The first thing I want to do is fix the known bug in ungetc, and I
> think the easiest way to do that is to make __toread set valid read
> buffer pointers when it fails due to eof status. Then, instead of
> ungetc checking the return value of __toread, it can instead call
> __toread and then just check rpos. That is, instead of:
> 
> 	if ((!f->rend && __toread(f)) || f->rpos <= f->buf - UNGET) {
> 		// error
> 
> it can instead do:
> 
> 	if (!f->rend) __toread(f);
> 	if (f->rpos <= f->buf - UNGET) {
> 		// error
> 
> or perhaps:
> 
> 	if (!f->rpos) __toread(f);
> 	if (!f->rpos || f->rpos <= f->buf - UNGET) {
> 		// error
> 
> I like the second version better because it does not assume that a
> null pointer compares <= any valid pointer, which could be wrong if
> pointer <= is implemented as a signed comparison. [...]

I have a fix ready to commit here, but sometime between now and
release I think we need some tests for it. The immportant things to
test are that ungetc and ungetwc work correctly on newly-opened files,
files in the middle of reading from the buffer, and files at eof; that
they fail for files not opened in a mode compatible with reading; and
that the new __toread behavior doesn't allow getc or fread to read
when the eof flag is set for the file but the underlying fd has more
data available (in the real world this only happens on terminals or
growing files; the latter would be easier to test I think).

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.