This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/4416] New: setlocales can fail silentely
- From: "madcoder at debian dot org" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 23 Apr 2007 21:58:58 -0000
- Subject: [Bug libc/4416] New: setlocales can fail silentely
- Reply-to: sourceware-bugzilla at sourceware dot org
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'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 <stdio.h>
#include <locale.h>
int main(void)
{
const char *s;
s = setlocale(LC_ALL, "en_US.utf-8");
printf("%s\n", s);
return 0;
}
================================================
strace gives:
================================================
brk(0) = 0x601000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x2ac0f56dd000
uname({sys="Linux", node="artemis", ...}) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x2ac0f56de000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", 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("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20\324\1"..., 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("/usr/lib/locale/locale-archive", O_RDONLY) = -1 ENOENT (No such file or
directory)
open("/usr/share/locale/locale.alias", O_RDONLY) = -1 ENOENT (No such file or
directory)
open("/usr/lib/locale/en_US.utf-8/LC_IDENTIFICATION", O_RDONLY) = -1 ENOENT (No
such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_IDENTIFICATION", O_RDONLY) = -1 ENOENT (No
such file or directory)
open("/usr/lib/locale/en_US/LC_IDENTIFICATION", O_RDONLY) = -1 ENOENT (No such
file or directory)
open("/usr/lib/locale/en.utf-8/LC_IDENTIFICATION", O_RDONLY) = -1 ENOENT (No
such file or directory)
open("/usr/lib/locale/en.utf8/LC_IDENTIFICATION", O_RDONLY) = -1 ENOENT (No
such file or directory)
open("/usr/lib/locale/en/LC_IDENTIFICATION", O_RDONLY) = -1 ENOENT (No such
file or directory)
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
====================================================
I don'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.
--
Summary: setlocales can fail silentely
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: madcoder at debian dot org
CC: glibc-bugs at sources dot redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=4416
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.