Bug 9754 - fflush after ungetc not POSIX compliant
Summary: fflush after ungetc not POSIX compliant
Status: RESOLVED DUPLICATE of bug 5994
Alias: None
Product: glibc
Classification: Unclassified
Component: stdio (show other bugs)
Version: 2.8
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-17 13:39 UTC by Bruno Haible
Modified: 2014-07-01 21:13 UTC (History)
2 users (show)

See Also:
Host: x86_64-suse-linux
Target: x86_64-suse-linux
Build: x86_64-suse-linux
Last reconfirmed:
fweimer: security-


Attachments
test case (295 bytes, text/plain)
2009-01-17 13:39 UTC, Bruno Haible
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bruno Haible 2009-01-17 13:39:02 UTC
In an decision on 2009-01-08, see
<http://www.opengroup.org/austin/aardvark/latest/xshbug3.txt>,
the Austin group decided about the behaviour of fflush after ungetc.
The following wording was adopted:
  "For a stream open for reading, if the file is not already at
   EOF, and the file is one capable of seeking, the file offset
   of the underlying open file description shall be set to the
   file position of the stream, and any characters pushed back
   onto the stream by ungetc() or ungetwc() that have not
   subsequently been read from the stream shall be discarded."

In this situation, glibc correctly drops the pushed back characters
and correctly keeps the stream's position unchanged, but something
inside the stream becomes inconsistent: the next fgetc call returns
a wrong result.

To reproduce:
$ gcc -O -Wall bug.c -o bug
$ ./bug < bug.c; echo $?
file position before fflush: 1
file position after fflush:  1
character read: ' ' but expected '*'
5

Expected output:
file position before fflush: 1
file position after fflush:  1
0
Comment 1 Bruno Haible 2009-01-17 13:39:46 UTC
Created attachment 3668 [details]
test case
Comment 2 Eric Blake 2013-10-17 12:09:06 UTC
This bug is about the same issue as in 5994.

*** This bug has been marked as a duplicate of bug 5994 ***