Yury Gribov | 0ca65fd | 2015-05-28 09:24:33 +0000 | [diff] [blame] | 1 | // Test stopset overflow in strcspn function |
Reid Kleckner | 85220d0 | 2015-08-12 23:50:12 +0000 | [diff] [blame] | 2 | // RUN: %clang_asan %s -o %t && %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s |
Yury Gribov | 0ca65fd | 2015-05-28 09:24:33 +0000 | [diff] [blame] | 3 | |
| 4 | // Test intercept_strcspn asan option |
Reid Kleckner | 85220d0 | 2015-08-12 23:50:12 +0000 | [diff] [blame] | 5 | // RUN: %env_asan_opts=intercept_strspn=false %run %t 2>&1 |
Yury Gribov | 0ca65fd | 2015-05-28 09:24:33 +0000 | [diff] [blame] | 6 | |
| 7 | #include <assert.h> |
| 8 | #include <string.h> |
Yury Gribov | 8da1408 | 2015-10-22 08:10:56 +0000 | [diff] [blame] | 9 | #include <sanitizer/asan_interface.h> |
Yury Gribov | 0ca65fd | 2015-05-28 09:24:33 +0000 | [diff] [blame] | 10 | |
| 11 | int main(int argc, char **argv) { |
| 12 | size_t r; |
| 13 | char s1[] = "ab"; |
Yury Gribov | 8da1408 | 2015-10-22 08:10:56 +0000 | [diff] [blame] | 14 | char s2[4] = "abc"; |
| 15 | __asan_poison_memory_region ((char *)&s2[2], 2); |
Yury Gribov | 0ca65fd | 2015-05-28 09:24:33 +0000 | [diff] [blame] | 16 | r = strcspn(s1, s2); |
Kuba Mracek | 8ed2928 | 2017-03-30 00:41:09 +0000 | [diff] [blame] | 17 | // CHECK:'s2'{{.*}} <== Memory access at offset {{[0-9]+}} partially overflows this variable |
Yury Gribov | ef40f0b | 2015-06-10 07:16:02 +0000 | [diff] [blame] | 18 | assert(r == 0); |
Yury Gribov | 0ca65fd | 2015-05-28 09:24:33 +0000 | [diff] [blame] | 19 | return 0; |
| 20 | } |