Bug 10412 - undefined behavior when porting error()
Summary: undefined behavior when porting error()
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.10
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-18 13:13 UTC by Eric Blake
Modified: 2014-07-01 07:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
Avoid undefined behavior in error(). (1.10 KB, patch)
2009-07-18 13:14 UTC, Eric Blake
Details | Diff
update patch to work on mingw (1.10 KB, patch)
2009-07-18 13:38 UTC, Eric Blake
Details | Diff
update patch to take into account possible freopen(stdout) calls (1.16 KB, patch)
2009-11-22 18:44 UTC, Bruno Haible
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Blake 2009-07-18 13:13:19 UTC
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 UTC
Created attachment 4060 [details]
Avoid undefined behavior in error().
Comment 2 Eric Blake 2009-07-18 13:38:31 UTC
Created attachment 4061 [details]
update patch to work on mingw
Comment 3 Bruno Haible 2009-11-22 18:44:20 UTC
Created attachment 4407 [details]
update patch to take into account possible freopen(stdout) calls