This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/11357] New: SIGBUS in getenv().
- From: "pluto at agmk dot net" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 8 Mar 2010 12:31:04 -0000
- Subject: [Bug libc/11357] New: SIGBUS in getenv().
- Reply-to: sourceware-bugzilla at sourceware dot org
hi,
during development a cross platform appliaction on x86 workstation
i've enabled an alignemnt checking in cpu by setting bit 18 in eflags.
(see "AC" at http://en.wikipedia.org/wiki/FLAGS_register_(computing))
for detecting on x86 unaligned accesses prohibited by sparc and arm.
right after i've stuck with SIGBUS in glibc getenv() function.
here's a reduced testcase:
$ cat p.c
#include <stdlib.h>
int main()
{
#if defined( __GNUC__ )
#if defined( __i386__ )
/* enable alignment checking on x86 */
asm( "pushf\n\torl $0x40000,(%esp)\n\tpopf" );
#elif defined( __x86_64__ )
/* enable alignment checking on x86_64 */
asm( "pushf\n\torl $0x40000,(%rsp)\n\tpopf");
#endif
#endif
char const* p = getenv( "PATH" );
return ( p != NULL );
}
$ gcc -Wall p.c -g2 -o p
$ gdb ./p
Program received signal SIGBUS, Bus error.
getenv (name=0x40060e "TH") at getenv.c:84
84 uint16_t ep_start = *(uint16_t *) *ep;
(gdb) l
79 name += 2;
80
81 for (ep = __environ; *ep != NULL; ++ep)
82 {
83 #if _STRING_ARCH_unaligned
84 uint16_t ep_start = *(uint16_t *) *ep;
85 #else
86 uint16_t ep_start = (((unsigned char *) *ep)[0]
87 | (((unsigned char *) *ep)[1] << 8));
88 #endif
(gdb) p/x *ep
$5 = 0x7fffffffe5bb
it dies on unaligned u16 access.
--
Summary: SIGBUS in getenv().
Product: glibc
Version: 2.11
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: pluto at agmk dot net
CC: glibc-bugs at sources dot redhat dot com
GCC build triplet: x86_64-gnu-linux
GCC host triplet: x86_64-gnu-linux
GCC target triplet: x86_64-gnu-linux
http://sourceware.org/bugzilla/show_bug.cgi?id=11357
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.