Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 1 | // Test strict_string_checks option in strcasestr function |
| 2 | // RUN: %clang_asan %s -o %t && %run %t 2>&1 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 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 |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 5 | |
| 6 | // There's no interceptor for strcasestr on Windows |
| 7 | // XFAIL: win32 |
| 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); |
| 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 | } |