[PATCH] [compiler-rt] Add a symbolizer testcase for closed stdin/stdout

Kuba Brecka kuba.brecka at gmail.com
Sat Feb 28 03:37:34 PST 2015


This testcase just tests that the external symbolizer (llvm-symbolizer) can start and communicate correctly even when the program closed its stdin, stdout and stderr.

http://reviews.llvm.org/D7973

Files:
  test/asan/TestCases/closed-fds.cc

Index: test/asan/TestCases/closed-fds.cc
===================================================================
--- test/asan/TestCases/closed-fds.cc
+++ test/asan/TestCases/closed-fds.cc
@@ -0,0 +1,30 @@
+// 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 && ASAN_OPTIONS=log_path=%t.log:verbosity=2 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-OUTPUT
+// RUN: FileCheck %s --check-prefix=CHECK-FILE < %t.log.*
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+  fprintf(stderr, "Closing streams.\n");
+  close(STDIN_FILENO);
+  close(STDOUT_FILENO);
+  close(STDERR_FILENO);
+  fprintf(stderr, "Can you hear me now?\n");
+  char *x = (char*)malloc(10 * sizeof(char));
+  free(x);
+  x[argc] = 'X';  // BOOM
+  return 0;
+}
+
+// CHECK-OUTPUT: Closing streams.
+// CHECK-OUTPUT-NOT: Can you hear me now?
+// 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-9]]

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7973.20934.patch
Type: text/x-patch
Size: 1261 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150228/1d1a75d2/attachment.bin>


More information about the llvm-commits mailing list