Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140827111620.GY22308@port70.net>
Date: Wed, 27 Aug 2014 13:16:20 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: fgets behaviour after eof

the C standard requires that

"If end-of-file is encountered and no characters have been read into the
array, the contents of the array remain unchanged and a null pointer is
returned. If a read error occurs during the operation, the array contents
are indeterminate and a null pointer is returned."

but musl's fgets always terminates the buffer with \0 even after EOF,
this is easy to fix:

-       *p = 0;
+       if (s) *p = 0;

However the behaviour of fgets(s, 1, f) is unclear if feof(f) is true,
in this case nothing is read so fgets cannot "encounter" end-of-file,
so it may set s[0]=0 and return s or it could check feof and return 0.
(glibc does not check feof)

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.