Bug 10412

Summary: undefined behavior when porting error()
Product: glibc Reporter: Eric Blake <ebb9>
Component: libcAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: glibc-bugs
Priority: P2 Flags: fweimer: security-
Version: 2.10   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Attachments: Avoid undefined behavior in error().
update patch to work on mingw
update patch to take into account possible freopen(stdout) calls

Description Eric Blake 2009-07-18 13:13:19 IST
Within glibc, it is always safe to call fflush (stdout), even if stdout has been
previously closed.  However, POSIX does not require this guarantee, and there
are other platforms where attempting a flush in this situation causes a SIGSEGV:

http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/18046/focus=18052

Since gnulib ports the error.c file to many other platforms, but wants to keep
it in sync with glibc's version, it would be nice for glibc to apply this patch
for portability.  The attached patch makes the optimization of not calling fcntl
on glibc, while still fixing the crash from the original gnulib report.
Comment 1 Eric Blake 2009-07-18 13:14:21 IST
Created attachment 4060 [details]
Avoid undefined behavior in error().
Comment 2 Eric Blake 2009-07-18 13:38:31 IST
Created attachment 4061 [details]
update patch to work on mingw
Comment 3 Bruno Haible 2009-11-22 18:44:20 IST
Created attachment 4407 [details]
update patch to take into account possible freopen(stdout) calls