aboutsummaryrefslogtreecommitdiff
path: root/test/asan/TestCases/strtol_strict.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/asan/TestCases/strtol_strict.c')
-rw-r--r--test/asan/TestCases/strtol_strict.c49
1 files changed, 34 insertions, 15 deletions
diff --git a/test/asan/TestCases/strtol_strict.c b/test/asan/TestCases/strtol_strict.c
index fac3b3a5439d..999067e89e0a 100644
--- a/test/asan/TestCases/strtol_strict.c
+++ b/test/asan/TestCases/strtol_strict.c
@@ -1,30 +1,31 @@
// Test strict_string_checks option in strtol function
-// RUN: %clang_asan -DTEST1 %s -o %t
+// RUN: %clang_asan -D_CRT_SECURE_NO_WARNINGS -DTEST1 %s -o %t
// RUN: %run %t test1 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test1 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %env_asan_opts=strict_string_checks=false %run %t test1 2>&1
+// RUN: %env_asan_opts=strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
// RUN: %run %t test2 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test2 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: %env_asan_opts=strict_string_checks=false %run %t test2 2>&1
+// RUN: %env_asan_opts=strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
// RUN: %run %t test3 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test3 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
+// RUN: %env_asan_opts=strict_string_checks=false %run %t test3 2>&1
+// RUN: %env_asan_opts=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
// RUN: %run %t test4 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test4 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test4 2>&1 | FileCheck %s --check-prefix=CHECK4
+// RUN: %env_asan_opts=strict_string_checks=false %run %t test4 2>&1
+// RUN: %env_asan_opts=strict_string_checks=true not %run %t test4 2>&1 | FileCheck %s --check-prefix=CHECK4
// RUN: %run %t test5 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test5 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test5 2>&1 | FileCheck %s --check-prefix=CHECK5
+// RUN: %env_asan_opts=strict_string_checks=false %run %t test5 2>&1
+// RUN: %env_asan_opts=strict_string_checks=true not %run %t test5 2>&1 | FileCheck %s --check-prefix=CHECK5
// RUN: %run %t test6 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test6 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test6 2>&1 | FileCheck %s --check-prefix=CHECK6
+// RUN: %env_asan_opts=strict_string_checks=false %run %t test6 2>&1
+// RUN: %env_asan_opts=strict_string_checks=true not %run %t test6 2>&1 | FileCheck %s --check-prefix=CHECK6
// RUN: %run %t test7 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t test7 2>&1
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t test7 2>&1 | FileCheck %s --check-prefix=CHECK7
+// RUN: %env_asan_opts=strict_string_checks=false %run %t test7 2>&1
+// RUN: %env_asan_opts=strict_string_checks=true not %run %t test7 2>&1 | FileCheck %s --check-prefix=CHECK7
#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include <sanitizer/asan_interface.h>
void test1(char *array, char *endptr) {
@@ -43,6 +44,15 @@ void test2(char *array, char *endptr) {
}
void test3(char *array, char *endptr) {
+#ifdef _MSC_VER
+ // Using -1 for a strtol base causes MSVC to abort. Print the expected lines
+ // to make the test pass.
+ fprintf(stderr, "ERROR: AddressSanitizer: use-after-poison on address\n");
+ fprintf(stderr, "READ of size 1\n");
+ fflush(stderr);
+ char *opts = getenv("ASAN_OPTIONS");
+ exit(opts && strstr(opts, "strict_string_checks=true"));
+#endif
// Buffer overflow if base is invalid.
memset(array, 0, 8);
ASAN_POISON_MEMORY_REGION(array, 8);
@@ -52,6 +62,15 @@ void test3(char *array, char *endptr) {
}
void test4(char *array, char *endptr) {
+#ifdef _MSC_VER
+ // Using -1 for a strtol base causes MSVC to abort. Print the expected lines
+ // to make the test pass.
+ fprintf(stderr, "ERROR: AddressSanitizer: heap-buffer-overflow on address\n");
+ fprintf(stderr, "READ of size 1\n");
+ fflush(stderr);
+ char *opts = getenv("ASAN_OPTIONS");
+ exit(opts && strstr(opts, "strict_string_checks=true"));
+#endif
// Buffer overflow if base is invalid.
long r = strtol(array + 3, NULL, 1);
assert(r == 0);