1*7c3d14c8STreehugger Robot // Test strict_string_checks option in atoll function 2*7c3d14c8STreehugger Robot // RUN: %clang_asan %s -o %t 3*7c3d14c8STreehugger Robot // RUN: %run %t test1 2>&1 4*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=strict_string_checks=false %run %t test1 2>&1 5*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1 6*7c3d14c8STreehugger Robot // RUN: %run %t test2 2>&1 7*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=strict_string_checks=false %run %t test2 2>&1 8*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2 9*7c3d14c8STreehugger Robot // RUN: %run %t test3 2>&1 10*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=strict_string_checks=false %run %t test3 2>&1 11*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3 12*7c3d14c8STreehugger Robot 13*7c3d14c8STreehugger Robot // FIXME: Needs Windows interceptor. 14*7c3d14c8STreehugger Robot // XFAIL: win32 15*7c3d14c8STreehugger Robot 16*7c3d14c8STreehugger Robot #include <assert.h> 17*7c3d14c8STreehugger Robot #include <stdlib.h> 18*7c3d14c8STreehugger Robot #include <string.h> 19*7c3d14c8STreehugger Robot test1(char * array)20*7c3d14c8STreehugger Robotvoid test1(char *array) { 21*7c3d14c8STreehugger Robot // Last symbol is non-digit 22*7c3d14c8STreehugger Robot memset(array, '1', 10); 23*7c3d14c8STreehugger Robot array[9] = 'a'; 24*7c3d14c8STreehugger Robot long long r = atoll(array); 25*7c3d14c8STreehugger Robot assert(r == 111111111); 26*7c3d14c8STreehugger Robot } 27*7c3d14c8STreehugger Robot test2(char * array)28*7c3d14c8STreehugger Robotvoid test2(char *array) { 29*7c3d14c8STreehugger Robot // Single non-digit symbol 30*7c3d14c8STreehugger Robot array[9] = 'a'; 31*7c3d14c8STreehugger Robot long long r = atoll(array + 9); 32*7c3d14c8STreehugger Robot assert(r == 0); 33*7c3d14c8STreehugger Robot } 34*7c3d14c8STreehugger Robot test3(char * array)35*7c3d14c8STreehugger Robotvoid test3(char *array) { 36*7c3d14c8STreehugger Robot // Incorrect number format 37*7c3d14c8STreehugger Robot memset(array, ' ', 10); 38*7c3d14c8STreehugger Robot array[9] = '-'; 39*7c3d14c8STreehugger Robot array[8] = '-'; 40*7c3d14c8STreehugger Robot long long r = atoll(array); 41*7c3d14c8STreehugger Robot assert(r == 0); 42*7c3d14c8STreehugger Robot } 43*7c3d14c8STreehugger Robot main(int argc,char ** argv)44*7c3d14c8STreehugger Robotint main(int argc, char **argv) { 45*7c3d14c8STreehugger Robot char *array = (char*)malloc(10); 46*7c3d14c8STreehugger Robot if (argc != 2) return 1; 47*7c3d14c8STreehugger Robot if (!strcmp(argv[1], "test1")) test1(array); 48*7c3d14c8STreehugger Robot // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} 49*7c3d14c8STreehugger Robot // CHECK1: READ of size 11 50*7c3d14c8STreehugger Robot if (!strcmp(argv[1], "test2")) test2(array); 51*7c3d14c8STreehugger Robot // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} 52*7c3d14c8STreehugger Robot // CHECK2: READ of size 2 53*7c3d14c8STreehugger Robot if (!strcmp(argv[1], "test3")) test3(array); 54*7c3d14c8STreehugger Robot // CHECK3: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} 55*7c3d14c8STreehugger Robot // CHECK3: READ of size 11 56*7c3d14c8STreehugger Robot free(array); 57*7c3d14c8STreehugger Robot return 0; 58*7c3d14c8STreehugger Robot } 59