1 // Check that when the program closed its std(in|out|err), running the external 2 // symbolizer still works. 3 4 // RUN: rm -f %t.log.* 5 // RUN: %clangxx_asan -O0 %s -o %t 2>&1 && %env_asan_opts=log_path=%t.log:verbosity=2 not %run %t 2>&1 6 // RUN: FileCheck %s --check-prefix=CHECK-FILE < %t.log.* 7 8 // FIXME: copy %t.log back from the device and re-enable on Android. 9 // UNSUPPORTED: android 10 11 #include <assert.h> 12 #include <stdio.h> 13 #include <stdlib.h> 14 #include <string.h> 15 #include <unistd.h> 16 17 int main(int argc, char **argv) { 18 int result = fprintf(stderr, "Closing streams.\n"); 19 assert(result > 0); 20 close(STDIN_FILENO); 21 close(STDOUT_FILENO); 22 close(STDERR_FILENO); 23 result = fprintf(stderr, "Can you hear me now?\n"); 24 assert(result < 0); 25 char *x = (char *)malloc(10 * sizeof(char)); 26 free(x); 27 x[argc] = 'X'; // BOOM 28 // CHECK-FILE: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}} 29 // CHECK-FILE: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}} 30 // CHECK-FILE: {{WRITE of size 1 at 0x.* thread T0}} 31 // CHECK-FILE: {{ #0 0x.* in main .*closed-fds.cc:}}[[@LINE-4]] 32 return 0; 33 } 34