public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jb at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libfortran/46267] New: strerror() is not necessarily thread-safe
Date: Tue, 02 Nov 2010 11:17:00 -0000	[thread overview]
Message-ID: <bug-46267-4@http.gcc.gnu.org/bugzilla/> (raw)

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.


             reply	other threads:[~2010-11-02 11:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-02 11:17 jb at gcc dot gnu.org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-46267-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).