From 5c909fa013fc285f010a95e8d387e0ef3412da9c Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 30 Dec 2015 11:52:19 +0000 Subject: Vendor import of compiler-rt trunk r256633: https://llvm.org/svn/llvm-project/compiler-rt/trunk@256633 --- test/asan/TestCases/Posix/closed-fds.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/asan/TestCases/Posix/closed-fds.cc (limited to 'test/asan/TestCases/Posix/closed-fds.cc') diff --git a/test/asan/TestCases/Posix/closed-fds.cc b/test/asan/TestCases/Posix/closed-fds.cc new file mode 100644 index 000000000000..3bbe3d8e68e1 --- /dev/null +++ b/test/asan/TestCases/Posix/closed-fds.cc @@ -0,0 +1,33 @@ +// Check that when the program closed its std(in|out|err), running the external +// symbolizer still works. + +// RUN: rm -f %t.log.* +// RUN: %clangxx_asan -O0 %s -o %t 2>&1 && %env_asan_opts=log_path=%t.log:verbosity=2 not %run %t 2>&1 +// RUN: FileCheck %s --check-prefix=CHECK-FILE < %t.log.* + +// FIXME: copy %t.log back from the device and re-enable on Android. +// UNSUPPORTED: android + +#include +#include +#include +#include +#include + +int main(int argc, char **argv) { + int result = fprintf(stderr, "Closing streams.\n"); + assert(result > 0); + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); + result = fprintf(stderr, "Can you hear me now?\n"); + assert(result < 0); + char *x = (char *)malloc(10 * sizeof(char)); + free(x); + x[argc] = 'X'; // BOOM + // CHECK-FILE: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}} + // CHECK-FILE: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}} + // CHECK-FILE: {{WRITE of size 1 at 0x.* thread T0}} + // CHECK-FILE: {{ #0 0x.* in main .*closed-fds.cc:}}[[@LINE-4]] + return 0; +} -- cgit v1.2.3