Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 1 | // Test string s1 overflow in strcspn function |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 2 | // RUN: %clang_asan %s -o %t && %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] | 3 | |
| 4 | // Test intercept_strspn asan option |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 5 | // RUN: %env_asan_opts=intercept_strspn=false %run %t 2>&1 |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 6 | |
| 7 | #include <assert.h> |
| 8 | #include <string.h> |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 9 | #include <sanitizer/asan_interface.h> |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 10 | |
| 11 | int main(int argc, char **argv) { |
| 12 | size_t r; |
| 13 | char s2[] = "ab"; |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 14 | char s1[4] = "caB"; |
| 15 | __asan_poison_memory_region ((char *)&s1[2], 2); |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 16 | r = strcspn(s1, s2); |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 17 | // CHECK:'s1' <== Memory access at offset {{[0-9]+}} partially overflows this variable |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 18 | assert(r == 1); |
| 19 | return 0; |
| 20 | } |