This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/6712] New: Race condition in calling setlocale()
- From: "sharyathi at in dot ibm dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 1 Jul 2008 10:58:11 -0000
- Subject: [Bug libc/6712] New: Race condition in calling setlocale()
- Reply-to: sourceware-bugzilla at sourceware dot org
Description
During PHP engine development it was observed that a thread calling
strcmp() would crash if another thread was also calling setlocale().
The problem is difficult to reproduce, but the following is a
line-by-line analysis of where the race condition exists.
-----------------------------------------------------------------------
char *
setlocale (int category, const char *locale)
{
char *locale_path;
.......
/* Does user want name of current locale? */
if (locale == NULL)
return (char *) _nl_global_locale.__names[category];
if (strcmp (locale, _nl_global_locale.__names[category]) == 0)
<== SIGSEGVs while accessing _nl_global_locale
..........
if (category == LC_ALL)
{
..........
/* Protect global data. */
__libc_rwlock_wrlock (__libc_setlocale_lock);
..........
setname (LC_ALL, composite)
<== Frees the global variable _nl_global_locale.__names[category]
..........
/* Critical section left. */
__libc_rwlock_unlock (__libc_setlocale_lock);
} //category == LC_ALL
..........
} //setlocale end of function
-----------------------------------------------------------------------
Though setlocale() is not on the POSIX.1 list of async-signal safe
functions as in section 2.4.3
http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html#tag_02_04
It still needs to be thread safe according to section 2.9.1 in
http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_09.html
--
Summary: Race condition in calling setlocale()
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: sharyathi at in dot ibm dot com
CC: bmark at us dot ibm dot com,glibc-bugs at sources dot
redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=6712
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.