public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/46267] New: strerror() is not necessarily thread-safe
@ 2010-11-02 11:17 jb at gcc dot gnu.org
  2010-11-02 12:43 ` [Bug libfortran/46267] " jvdelisle at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: jb at gcc dot gnu.org @ 2010-11-02 11:17 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: jb@gcc.gnu.org


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.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-01-22 19:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-02 11:17 [Bug libfortran/46267] New: strerror() is not necessarily thread-safe jb at gcc dot gnu.org
2010-11-02 12:43 ` [Bug libfortran/46267] " jvdelisle at gcc dot gnu.org
2010-11-02 13:06 ` redi at gcc dot gnu.org
2010-11-02 13:20 ` jb at gcc dot gnu.org
2010-11-02 13:41 ` jakub at gcc dot gnu.org
2011-01-20 15:14 ` jb at gcc dot gnu.org
2011-01-20 18:59 ` jb at gcc dot gnu.org
2011-01-21 17:37 ` jb at gcc dot gnu.org
2011-01-21 23:01 ` jb at gcc dot gnu.org
2011-01-22 21:10 ` jb at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).