aboutsummaryrefslogtreecommitdiff
path: root/test/asan/TestCases/strdup_oob_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/asan/TestCases/strdup_oob_test.cc')
-rw-r--r--test/asan/TestCases/strdup_oob_test.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/asan/TestCases/strdup_oob_test.cc b/test/asan/TestCases/strdup_oob_test.cc
new file mode 100644
index 000000000000..a039568b2245
--- /dev/null
+++ b/test/asan/TestCases/strdup_oob_test.cc
@@ -0,0 +1,20 @@
+// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+#include <string.h>
+
+char kString[] = "foo";
+
+int main(int argc, char **argv) {
+ char *copy = strdup(kString);
+ int x = copy[4 + argc]; // BOOM
+ // CHECK: AddressSanitizer: heap-buffer-overflow
+ // CHECK: #0 {{.*}}main {{.*}}strdup_oob_test.cc:[[@LINE-2]]
+ // CHECK-LABEL: allocated by thread T{{.*}} here:
+ // CHECK: #{{[01]}} {{.*}}strdup
+ // CHECK-LABEL: SUMMARY
+ // CHECK: strdup_oob_test.cc:[[@LINE-6]]
+ return x;
+}