Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 1 | // Test strict_string_checks option in strstr 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 | #include <assert.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <string.h> |
| 9 | |
| 10 | int main(int argc, char **argv) { |
| 11 | size_t size = 100; |
| 12 | char fill = 'o'; |
| 13 | char *s1 = (char*)malloc(size); |
| 14 | char *s2 = (char*)malloc(size); |
| 15 | memset(s1, fill, size); |
| 16 | memset(s2, fill, size); |
| 17 | s2[size - 1]='\0'; |
| 18 | char* r = strstr(s1, s2); |
| 19 | // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} |
| 20 | // CHECK: READ of size 101 |
| 21 | assert(r == s1); |
| 22 | free(s1); |
| 23 | free(s2); |
| 24 | return 0; |
| 25 | } |