summaryrefslogtreecommitdiff
path: root/test/asan/TestCases/Linux/bcmp_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/asan/TestCases/Linux/bcmp_test.cc')
-rw-r--r--test/asan/TestCases/Linux/bcmp_test.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/asan/TestCases/Linux/bcmp_test.cc b/test/asan/TestCases/Linux/bcmp_test.cc
new file mode 100644
index 000000000..61853f08f
--- /dev/null
+++ b/test/asan/TestCases/Linux/bcmp_test.cc
@@ -0,0 +1,23 @@
+// RUN: %clangxx_asan %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=A1
+// RUN: not %run %t 1 2>&1 | FileCheck %s --check-prefix=A2
+// RUN: %env_asan_opts=intercept_memcmp=0 %run %t
+
+#include <strings.h>
+int main(int argc, char **argv) {
+ char a1[] = {1, 2, 3, 4, 5, 6, 7, 8};
+ char a2[] = {3, 4, 5, 6, 7, 8, 9};
+ int res;
+ if (argc == 1)
+ res = bcmp(a1, a2, sizeof(a1)); // BOOM
+ else
+ res = bcmp(a2, a1, sizeof(a1)); // BOOM
+ // A1: AddressSanitizer: stack-buffer-overflow
+ // A1: {{#0.*memcmp}}
+ // A1: 'a2' <== Memory access at offset
+ //
+ // A2: AddressSanitizer: stack-buffer-overflow
+ // A2: {{#0.*memcmp}}
+ // A2: 'a2' <== Memory access at offset
+ return res == 0;
+}