diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:52:19 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:52:19 +0000 |
commit | 5c909fa013fc285f010a95e8d387e0ef3412da9c (patch) | |
tree | 1059d068ad281f4776ff44cd414574f99a460023 /test/asan/TestCases/strtol_strict.c | |
parent | f31bcc68c72371a2bf63aead9f3373a1ff2053b6 (diff) | |
download | src-5c909fa013fc285f010a95e8d387e0ef3412da9c.tar.gz src-5c909fa013fc285f010a95e8d387e0ef3412da9c.zip |
Notes
Diffstat (limited to 'test/asan/TestCases/strtol_strict.c')
-rw-r--r-- | test/asan/TestCases/strtol_strict.c | 49 |
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); |