lewisje / address-sanitizer

Automatically exported from code.google.com/p/address-sanitizer
0 stars 0 forks source link

chdir breaks symbolization of dynamic libraries #405

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The program is:

// 1.c
#include <unistd.h>
#include <dlfcn.h>

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 <stdlib.h>
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.

Original issue reported on code.google.com by dvyu...@google.com on 20 Aug 2015 at 6:10