<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://sourceware.org/bugzilla/bugzilla.dtd">

<bugzilla version="4.0.10"
          urlbase="http://sourceware.org/bugzilla/"
          
          maintainer="overseers@sourceware.org"
>

    <bug>
          <bug_id>4416</bug_id>
          
          <creation_ts>2007-04-23 22:58:00 +0000</creation_ts>
          <short_desc>setlocales can fail silentely</short_desc>
          <delta_ts>2007-04-24 10:14:33 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>glibc</product>
          <component>libc</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Pierre Habouzit">madcoder</reporter>
          <assigned_to name="Ulrich Drepper">drepper.fsp</assigned_to>
          <cc>glibc-bugs</cc>
          <cf_gcchost></cf_gcchost>
          <cf_gcctarget></cf_gcctarget>
          <cf_gccbuild></cf_gccbuild>
          

      

      

      

          <long_desc isprivate="0">
            <commentid>16552</commentid>
            <who name="Pierre Habouzit">madcoder</who>
            <bug_when>2007-04-23 22:58:58 +0000</bug_when>
            <thetext>When Virtual Memory is low, the mmap of /usr/lib/locale/locale-archive can fail 
(in loadarchive.c, function _nl_load_locale_from_archive).

Then, _nl_find_locale (findlocale.c) tries to recover from that, trying to 
guess pathes or sth like that on its own. But it still fails because it can&apos;t 
find LC_IDENTIFICATION files and setlocale returns something completely broken.

You can emulate that by renaming /usr/lib/locale/locale-archive. A sample 
problematic program is:

================================================
#include &lt;stdio.h&gt;
#include &lt;locale.h&gt;

int main(void)
{
    const char *s;

    s = setlocale(LC_ALL, &quot;en_US.utf-8&quot;);
    printf(&quot;%s\n&quot;, s);
    return 0;
}
================================================


strace gives:

================================================
brk(0)                                  = 0x601000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x2ac0f56dd000
uname({sys=&quot;Linux&quot;, node=&quot;artemis&quot;, ...}) = 0
access(&quot;/etc/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x2ac0f56de000
access(&quot;/etc/ld.so.preload&quot;, R_OK)      = -1 ENOENT (No such file or directory)
open(&quot;/etc/ld.so.cache&quot;, O_RDONLY)      = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=57422, ...}) = 0
mmap(NULL, 57422, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2ac0f56e0000
close(3)                                = 0
access(&quot;/etc/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory)
open(&quot;/lib/libc.so.6&quot;, O_RDONLY)        = 3
read(3, &quot;\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0&gt;\0\1\0\0\0\20\324\1&quot;..., 832) = 
832
fstat(3, {st_mode=S_IFREG|0755, st_size=1359200, ...}) = 0
mmap(NULL, 2416808, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0x2ac0f57de000
mprotect(0x2ac0f5924000, 1044480, PROT_NONE) = 0
mmap(0x2ac0f5a23000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|
MAP_DENYWRITE, 3, 0x145000) = 0x2ac0f5a23000
mmap(0x2ac0f5a28000, 16552, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|
MAP_ANONYMOUS, -1, 0) = 0x2ac0f5a28000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x2ac0f5a2d000
arch_prctl(ARCH_SET_FS, 0x2ac0f5a2d6f0) = 0
mprotect(0x2ac0f5a23000, 12288, PROT_READ) = 0
munmap(0x2ac0f56e0000, 57422)           = 0
brk(0)                                  = 0x601000
brk(0x622000)                           = 0x622000
open(&quot;/usr/lib/locale/locale-archive&quot;, O_RDONLY) = -1 ENOENT (No such file or 
directory)
open(&quot;/usr/share/locale/locale.alias&quot;, O_RDONLY) = -1 ENOENT (No such file or 
directory)
open(&quot;/usr/lib/locale/en_US.utf-8/LC_IDENTIFICATION&quot;, O_RDONLY) = -1 ENOENT (No 
such file or directory)
open(&quot;/usr/lib/locale/en_US.utf8/LC_IDENTIFICATION&quot;, O_RDONLY) = -1 ENOENT (No 
such file or directory)
open(&quot;/usr/lib/locale/en_US/LC_IDENTIFICATION&quot;, O_RDONLY) = -1 ENOENT (No such 
file or directory)
open(&quot;/usr/lib/locale/en.utf-8/LC_IDENTIFICATION&quot;, O_RDONLY) = -1 ENOENT (No 
such file or directory)
open(&quot;/usr/lib/locale/en.utf8/LC_IDENTIFICATION&quot;, O_RDONLY) = -1 ENOENT (No 
such file or directory)
open(&quot;/usr/lib/locale/en/LC_IDENTIFICATION&quot;, O_RDONLY) = -1 ENOENT (No such 
file or directory)
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
====================================================

I don&apos;t expect setlocale especially to success even with low memory, but at 
least it should fail (return NULL) to express the fact that it only loaded C 
locale.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>16560</commentid>
            <who name="Pierre Habouzit">madcoder</who>
            <bug_when>2007-04-24 11:14:33 +0000</bug_when>
            <thetext>ahem, I was testing on a 2.3 libc rather than the 2.5 sorry, it seems to work 
fine now.</thetext>
          </long_desc>
      
      

    </bug>

</bugzilla>