http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46267
Summary: strerror() is not necessarily thread-safe
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libfortran
AssignedTo: [email protected]
ReportedBy: [email protected]
In libgfortran/io/unix.c (get_oserror) strerror() is called. However, according
to POSIX
http://www.opengroup.org/onlinepubs/9699919799/functions/strerror.html
"The strerror() function need not be thread-safe."
Possible solutions
- On some targets such as Solaris 9 strerror() is thread-safe.
- On Windows there is apparently a thread-safe strerror_s() function.
- POSIX has the thread-safe strerror_r() function. Unfortunately it suffers
from a few issues.
1) The interface is a bit cumbersome, the caller must allocate a buffer for
the message and pass it in
2) glibc has also another strerror_r() function with an incompatible
interface. Thus one needs to do some macro trickery to use the POSIX version,
or then use the GNU version on glibc targets.
In short, it's a trainwreck. See e.g.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6223913 and
https://www.securecoding.cert.org/confluence/display/seccode/CON33-C.+Avoid+race+conditions+when+using+library+functions
- POSIX 2008 has the strerror_l() function which is thread-safe and has a
similar interface as strerror(). Using this, if available, is perhaps the
simplest solution and should at least fix the issue on platforms which have
this function.