1 // Test strict_string_checks option in strcasestr function
2 // RUN: %clang_asan %s -o %t && %run %t 2>&1
3 // RUN: %env_asan_opts=strict_string_checks=false %run %t 2>&1
4 // RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s
5 
6 // There's no interceptor for strcasestr on Windows
7 // XFAIL: windows-msvc
8 
9 #define _GNU_SOURCE
10 #include <assert.h>
11 #include <stdlib.h>
12 #include <string.h>
13 
main(int argc,char ** argv)14 int main(int argc, char **argv) {
15   size_t size = 100;
16   char *s1 = (char*)malloc(size);
17   char *s2 = (char*)malloc(size);
18   memset(s1, 'o', size);
19   memset(s2, 'O', size);
20   s2[size - 1]='\0';
21   char* r = strcasestr(s1, s2);
22   // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
23   // CHECK: READ of size 101
24   assert(r == s1);
25   free(s1);
26   free(s2);
27   return 0;
28 }
29