From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15374 invoked by alias); 2 Nov 2010 11:17:37 -0000 Received: (qmail 15350 invoked by uid 22791); 2 Nov 2010 11:17:35 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 02 Nov 2010 11:17:31 +0000 From: "jb at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libfortran/46267] New: strerror() is not necessarily thread-safe X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libfortran X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jb at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Tue, 02 Nov 2010 11:17:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-11/txt/msg00090.txt.bz2 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.