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

* [Bug libfortran/46267] strerror() is not necessarily thread-safe
  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 ` jvdelisle at gcc dot gnu.org
  2010-11-02 13:06 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2010-11-02 12:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46267

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jvdelisle at gcc dot
                   |                            |gnu.org

--- Comment #1 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2010-11-02 12:43:13 UTC ---
I see strerror used in two places:

./intrinsics/gerror.c:  p = strerror (errno);
./io/unix.c:  return strerror (errno);

There seems to be some configury already in config.h.in for something here.

Can we simply define _GNU_SOURCE to get strerror_r and then just use it?


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

* [Bug libfortran/46267] strerror() is not necessarily thread-safe
  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
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2010-11-02 13:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46267

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-02 13:06:22 UTC ---
(In reply to comment #1)
> Can we simply define _GNU_SOURCE to get strerror_r and then just use it?

What about non-glibc systems?


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

* [Bug libfortran/46267] strerror() is not necessarily thread-safe
  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
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jb at gcc dot gnu.org @ 2010-11-02 13:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46267

--- Comment #3 from Janne Blomqvist <jb at gcc dot gnu.org> 2010-11-02 13:20:48 UTC ---
Well, if we want to use strerror_r() we'd have to either first undef
_GNU_SOURCE before we include string.h so that we get the POSIX version (but,
might this cause some other weird breakage?) or then we need to have versions
both for glibc and others. E.g.

#ifdef HAVE_STRERROR_R
#ifdef _GNU_SOURCE
// Use glibc strerror_r()
#else
// Use POSIX strerror_r()
#else
// Use strerror()
#endif


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

* [Bug libfortran/46267] strerror() is not necessarily thread-safe
  2010-11-02 11:17 [Bug libfortran/46267] New: strerror() is not necessarily thread-safe jb at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-11-02 13:41 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46267

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2010-11-02 13:41:10 UTC ---
Testing _GNU_SOURCE macro is not the right way to differentiate GNU vs. POSIX
2008 strerror_r, GNU version is used unless POSIX 2008 is requested without
_GNU_SOURCE.  I guess much easier would be to check the return type of
strerror_r instead.
#ifdef HAVE_STRERROR_R
if (__builtin_classify_type (strerror_r (0, NULL, 0)) == 5)
  /* GNU strerror_r */;
else
  /* POSIX strerror_r */;
#endif


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

* [Bug libfortran/46267] strerror() is not necessarily thread-safe
  2010-11-02 11:17 [Bug libfortran/46267] New: strerror() is not necessarily thread-safe jb at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jb at gcc dot gnu.org @ 2011-01-20 15:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46267

Janne Blomqvist <jb at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011.01.20 14:44:26
     Ever Confirmed|0                           |1

--- Comment #5 from Janne Blomqvist <jb at gcc dot gnu.org> 2011-01-20 14:44:26 UTC ---
Assigning to myself.


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

* [Bug libfortran/46267] strerror() is not necessarily thread-safe
  2010-11-02 11:17 [Bug libfortran/46267] New: strerror() is not necessarily thread-safe jb at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jb at gcc dot gnu.org @ 2011-01-20 18:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46267

Janne Blomqvist <jb at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |http://gcc.gnu.org/ml/gcc-p
                   |                            |atches/2011-01/msg01400.htm
                   |                            |l

--- Comment #6 from Janne Blomqvist <jb at gcc dot gnu.org> 2011-01-20 18:14:17 UTC ---
Patch: http://gcc.gnu.org/ml/gcc-patches/2011-01/msg01400.html


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

* [Bug libfortran/46267] strerror() is not necessarily thread-safe
  2010-11-02 11:17 [Bug libfortran/46267] New: strerror() is not necessarily thread-safe jb at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  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
  8 siblings, 0 replies; 10+ messages in thread
From: jb at gcc dot gnu.org @ 2011-01-21 17:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46267

Janne Blomqvist <jb at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|http://gcc.gnu.org/ml/gcc-p |http://gcc.gnu.org/ml/gcc-p
                   |atches/2011-01/msg01400.htm |atches/2011-01/msg01486.htm
                   |l                           |l
         AssignedTo|unassigned at gcc dot       |jb at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #7 from Janne Blomqvist <jb at gcc dot gnu.org> 2011-01-21 17:26:08 UTC ---
Updated patch: http://gcc.gnu.org/ml/gcc-patches/2011-01/msg01486.html


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

* [Bug libfortran/46267] strerror() is not necessarily thread-safe
  2010-11-02 11:17 [Bug libfortran/46267] New: strerror() is not necessarily thread-safe jb at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  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
  8 siblings, 0 replies; 10+ messages in thread
From: jb at gcc dot gnu.org @ 2011-01-21 23:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46267

--- Comment #8 from Janne Blomqvist <jb at gcc dot gnu.org> 2011-01-21 22:42:26 UTC ---
Author: jb
Date: Fri Jan 21 22:42:17 2011
New Revision: 169110

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169110
Log:
PR 46267 strerror thread safety

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/config.h.in
    trunk/libgfortran/configure
    trunk/libgfortran/configure.ac
    trunk/libgfortran/intrinsics/gerror.c
    trunk/libgfortran/io/unix.c
    trunk/libgfortran/libgfortran.h
    trunk/libgfortran/runtime/error.c


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

* [Bug libfortran/46267] strerror() is not necessarily thread-safe
  2010-11-02 11:17 [Bug libfortran/46267] New: strerror() is not necessarily thread-safe jb at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2011-01-21 23:01 ` jb at gcc dot gnu.org
@ 2011-01-22 21:10 ` jb at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jb at gcc dot gnu.org @ 2011-01-22 21:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46267

Janne Blomqvist <jb at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #9 from Janne Blomqvist <jb at gcc dot gnu.org> 2011-01-22 18:59:41 UTC ---
Fixed, closing


^ 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).