google / google/sanitizers

chdir breaks symbolization of dynamic libraries

Open
#405 2 comments 0 reactions 1 assignee Claimed by @dvyukov View on GitHub
Priority-Medium ProjectAddressSanitizer Status-Accepted Type-Defect
Dominant language
C
Stars
12.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Originally reported on Google Code with ID 405

```
The program is:

// 1.c
#include
#include

int main() {
void *handle = dlopen("./s.so", RTLD_LAZY);
void (*f)() = (void (*)())dlsym(handle, "run");
chdir("/tmp"); // breaks symbolization
(*f)();
return 0;
}

// 2.c
#include
void run() {
void *p = malloc(1);
*(volatile int *)p = 42;
}

Build as:

$ clang -fsanitize=address 1.c -g
$ clang -fsanitize=address 2.c -o s.so -shared -fPIC -g

When run s.so is not symbolized:

$ ./a.out

==7130==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000efd0 at
pc 0x7ffaeaafe7eb bp 0x7ffc4faf8500 sp 0x7ffc4faf84f8
WRITE of size 4 at 0x60200000efd0 thread T0
LLVMSymbolizer: error reading file: No such file or directory.
#0 0x7ffaeaafe7ea (s.so+0x7ea)
#1 0x4ddc24 in main /tmp/111.c:8:3
#2 0x7ffaed3e4ec4 in __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:287
#3 0x4186e5 in _start (/usr/local/google/home/dvyukov/src/llvm/a.out+0x4186e5)

If chdir is commented out, then s.so is symbolized.

```

Reported by `dvyukov@google.com` on 2015-08-20 18:10:22

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.