1 // Test strict_string_checks option in atoll function
2 // RUN: %clang_asan %s -o %t
3 // RUN: %run %t test1 2>&1
4 // RUN: %env_asan_opts=strict_string_checks=false %run %t test1 2>&1
5 // RUN: %env_asan_opts=strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
6 // RUN: %run %t test2 2>&1
7 // RUN: %env_asan_opts=strict_string_checks=false %run %t test2 2>&1
8 // RUN: %env_asan_opts=strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
9 // RUN: %run %t test3 2>&1
10 // RUN: %env_asan_opts=strict_string_checks=false %run %t test3 2>&1
11 // RUN: %env_asan_opts=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
13 // FIXME: Needs Windows interceptor.
20 void test1(char *array) {
21 // Last symbol is non-digit
22 memset(array, '1', 10);
24 long long r = atoll(array);
25 assert(r == 111111111);
28 void test2(char *array) {
29 // Single non-digit symbol
31 long long r = atoll(array + 9);
35 void test3(char *array) {
36 // Incorrect number format
37 memset(array, ' ', 10);
40 long long r = atoll(array);
44 int main(int argc, char **argv) {
45 char *array = (char*)malloc(10);
46 if (argc != 2) return 1;
47 if (!strcmp(argv[1], "test1")) test1(array);
48 // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
49 // CHECK1: READ of size 11
50 if (!strcmp(argv[1], "test2")) test2(array);
51 // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
52 // CHECK2: READ of size 2
53 if (!strcmp(argv[1], "test3")) test3(array);
54 // CHECK3: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
55 // CHECK3: READ of size 11