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: target={{.*windows-(msvc.*|gnu)}} |
8 | |
9 | #define _GNU_SOURCE |
10 | #include <assert.h> |
11 | #include <stdlib.h> |
12 | #include <string.h> |
13 | |
14 | int main(int argc, char **argv) { |
15 | size_t size = 100; |
16 | char *s1 = (char*)malloc(size: size); |
17 | char *s2 = (char*)malloc(size: size); |
18 | memset(s: s1, c: 'o', n: size); |
19 | memset(s: s2, c: 'O', n: size); |
20 | s2[size - 1]='\0'; |
21 | char* r = strcasestr(haystack: s1, needle: s2); |
22 | // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} |
23 | // CHECK: READ of size 101 |
24 | assert(r == s1); |
25 | free(ptr: s1); |
26 | free(ptr: s2); |
27 | return 0; |
28 | } |
29 | |