Fix ASan tests.
authorMaxim Ostapenko <m.ostapenko@samsung.com>
Thu, 4 Aug 2016 08:27:22 +0000 (11:27 +0300)
committerIvan Baravy <i.baravy@samsung.com>
Mon, 27 Feb 2017 08:02:08 +0000 (11:02 +0300)
Some ASan tests fail due to:
1) Unable to unwind malloc trace.
2) Return invalid code due to hant_on_error=false enabled by default.

Let's fix this.

Change-Id: I634c5bff0e21a693a4168eaa12f443cee114a83e
Signed-off-by: Maxim Ostapenko <m.ostapenko@samsung.com>
gcc/testsuite/c-c++-common/asan/heap-overflow-1.c
gcc/testsuite/c-c++-common/asan/pr61530.c
gcc/testsuite/c-c++-common/asan/pr70541.c
gcc/testsuite/c-c++-common/asan/sanity-check-pure-c-1.c
gcc/testsuite/c-c++-common/asan/strncpy-overflow-1.c
gcc/testsuite/c-c++-common/asan/use-after-free-1.c
gcc/testsuite/g++.dg/asan/deep-stack-uaf-1.C
gcc/testsuite/g++.dg/asan/interception-malloc-test-1.C
gcc/testsuite/g++.dg/asan/interception-test-1.C

index 0377a6c..d6ad803 100644 (file)
@@ -10,6 +10,11 @@ void *memset (void *, int, __SIZE_TYPE__);
 void *malloc (__SIZE_TYPE__);
 void free (void *);
 
+const char *
+__asan_default_options () {
+  return "fast_unwind_on_malloc=false";
+}
+
 #ifdef __cplusplus
 }
 #endif
@@ -24,8 +29,8 @@ int main(int argc, char **argv) {
 }
 
 /* { dg-output "READ of size 1 at 0x\[0-9a-f\]+ thread T0.*(\n|\r\n|\r)" } */
-/* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*heap-overflow-1.c:21|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
+/* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*heap-overflow-1.c:26|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*0x\[0-9a-f\]+ is located 0 bytes to the right of 10-byte region\[^\n\r]*(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*allocated by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */
 /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
-/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*heap-overflow-1.c:19|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*heap-overflow-1.c:24|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
index e306a71..445bca4 100644 (file)
@@ -3,7 +3,7 @@
 
 __attribute__((noinline,noclone)) void
 foo (char *a, char *b) {
-  a[0] = b[0] = 0;
+  a[0] = b[0] = 1;
   __builtin_memcpy(a, b, 4);
 }
 
@@ -11,7 +11,7 @@ int
 main () {
   char a, b;
   foo (&a, &b);
-  return 0;
+  return a;
 }
 
 /* { dg-output "ERROR: AddressSanitizer: stack-buffer-overflow" } */
index b2a4bd5..464a1f1 100644 (file)
@@ -6,6 +6,19 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const char *
+__asan_default_options () {
+  return "fast_unwind_on_malloc=false";
+}
+
+#ifdef __cplusplus
+}
+#endif
+
 struct Simple {
   int value;
 };
@@ -25,10 +38,10 @@ int main() {
 /* { dg-output "ERROR: AddressSanitizer:? heap-use-after-free on address\[^\n\r]*" } */
 /* { dg-output "0x\[0-9a-f\]+ at pc 0x\[0-9a-f\]+ bp 0x\[0-9a-f\]+ sp 0x\[0-9a-f\]+\[^\n\r]*(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*READ of size 4 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" } */
-/* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*pr70541.c:21|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
+/* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*pr70541.c:34|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*freed by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */
 /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)free|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
-/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*pr70541.c:20|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
+/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*pr70541.c:33|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*previously allocated by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */
 /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
-/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*pr70541.c:18|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*pr70541.c:31|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
index 219fcf8..aa044a5 100644 (file)
@@ -3,6 +3,20 @@
 /* { dg-shouldfail "asan" } */
 
 #include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const char *
+__asan_default_options () {
+  return "fast_unwind_on_malloc=false";
+}
+
+#ifdef __cplusplus
+}
+#endif
+
 int main() {
   char *x = (char*)malloc(10);
   free(x);
@@ -11,6 +25,6 @@ int main() {
 
 /* { dg-output "heap-use-after-free.*(\n|\r\n|\r)" } */
 /* { dg-output "    #0 \[^\n\r]*(in _*(interceptor_|wrap_)free|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
-/* { dg-output "    #1 \[^\n\r]*(in _*main (\[^\n\r]*sanity-check-pure-c-1.c:8|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
+/* { dg-output "    #1 \[^\n\r]*(in _*main (\[^\n\r]*sanity-check-pure-c-1.c:22|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
 /* { dg-output "    #0 \[^\n\r]*(in _*(interceptor_|wrap_)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
-/* { dg-output "    #1 \[^\n\r]*(in _*main (\[^\n\r]*sanity-check-pure-c-1.c:7|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "    #1 \[^\n\r]*(in _*main (\[^\n\r]*sanity-check-pure-c-1.c:21|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
index 45759ae..333035a 100644 (file)
@@ -4,18 +4,32 @@
 
 #include <string.h>
 #include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const char *
+__asan_default_options () {
+  return "fast_unwind_on_malloc=false";
+}
+
+#ifdef __cplusplus
+}
+#endif
+
 int main(int argc, char **argv) {
   char *hello = (char*)malloc(6);
   strcpy(hello, "hello");
   char *short_buffer = (char*)malloc(9);
   strncpy(short_buffer, hello, 10);  /* BOOM */
-  return short_buffer[8];
+  return short_buffer[0];
 }
 
 /* { dg-output "WRITE of size \[0-9\]* at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" } */
 /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)strncpy|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
-/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*strncpy-overflow-1.c:11|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
+/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*strncpy-overflow-1.c:25|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*0x\[0-9a-f\]+ is located 0 bytes to the right of 9-byte region\[^\n\r]*(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*allocated by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */
 /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
-/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*strncpy-overflow-1.c:10|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*strncpy-overflow-1.c:24|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
index 75d8f9f..f83bf6d 100644 (file)
@@ -3,6 +3,20 @@
 /* { dg-shouldfail "asan" } */
 
 #include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const char *
+__asan_default_options () {
+  return "fast_unwind_on_malloc=false";
+}
+
+#ifdef __cplusplus
+}
+#endif
+
 int main() {
   char *x = (char*)malloc(10);
   free(x);
@@ -12,11 +26,11 @@ int main() {
 /* { dg-output "ERROR: AddressSanitizer:? heap-use-after-free on address\[^\n\r]*" } */
 /* { dg-output "0x\[0-9a-f\]+ at pc 0x\[0-9a-f\]+ bp 0x\[0-9a-f\]+ sp 0x\[0-9a-f\]+\[^\n\r]*(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*READ of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" } */
-/* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*use-after-free-1.c:9|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
+/* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*use-after-free-1.c:23|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*0x\[0-9a-f\]+ is located 5 bytes inside of 10-byte region .0x\[0-9a-f\]+,0x\[0-9a-f\]+\[^\n\r]*(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*freed by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */
 /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)free|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
-/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*use-after-free-1.c:8|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
+/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*use-after-free-1.c:22|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
 /* { dg-output "\[^\n\r]*previously allocated by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */
 /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
-/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*use-after-free-1.c:7|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*use-after-free-1.c:21|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
index 4ae91f7..b1057a8 100644 (file)
@@ -2,7 +2,7 @@
 
 // { dg-do run }
 // { dg-skip-if "" { *-*-* } { "-flto" } { "" } }
-// { dg-set-target-env-var ASAN_OPTIONS "malloc_context_size=120:redzone=512" }
+// { dg-set-target-env-var ASAN_OPTIONS "malloc_context_size=120:redzone=512:fast_unwind_on_malloc=false" }
 // { dg-options "-fno-omit-frame-pointer -fno-optimize-sibling-calls" }
 // { dg-additional-options "-mno-omit-leaf-frame-pointer" { target { i?86-*-* x86_64-*-* } } }
 // { dg-shouldfail "asan" }
index e64c184..117d34a 100644 (file)
@@ -18,7 +18,7 @@ extern "C" void *malloc(size_t size) {
 int main() {
   char *x = (char*)malloc(10);
   free(x);
-  return (int)strtol(x, 0, 10);
+  return (int)strtol(x, 0, 10) != 0xdeadbeef;
 }
 
 // { dg-output "malloc call.*(\n|\r\n|\r)" }
index 79248e0..57c25db 100644 (file)
@@ -3,8 +3,8 @@
 // { dg-do run }
 // { dg-options "-fno-builtin-malloc -fno-builtin-free" }
 // { dg-additional-options "-D__NO_INLINE__" { target { *-*-linux-gnu } } }
-// { dg-shouldfail "asan" }
 // { dg-skip-if "Darwin uses mac function interposition" { *-*-darwin* } }
+// { dg-shouldfail "asan" }
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -18,7 +18,7 @@ extern "C" long strtol(const char *nptr, char **endptr, int base) {
 int main() {
   char *x = (char*)malloc(10);
   free(x);
-  return (int)strtol(x, 0, 10);
+  return (int)strtol(x, 0, 10) != 0xdeadbeef;
 }
 
 // { dg-output "my_strtol_interceptor.*(\n|\r\n|\r)" }