xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/strcspn-2.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // Test stopset overflow in strcspn function
2*7c3d14c8STreehugger Robot // RUN: %clang_asan %s -o %t && %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s
3*7c3d14c8STreehugger Robot 
4*7c3d14c8STreehugger Robot // Test intercept_strcspn asan option
5*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=intercept_strspn=false %run %t 2>&1
6*7c3d14c8STreehugger Robot 
7*7c3d14c8STreehugger Robot #include <assert.h>
8*7c3d14c8STreehugger Robot #include <string.h>
9*7c3d14c8STreehugger Robot #include <sanitizer/asan_interface.h>
10*7c3d14c8STreehugger Robot 
main(int argc,char ** argv)11*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
12*7c3d14c8STreehugger Robot   size_t r;
13*7c3d14c8STreehugger Robot   char s1[] = "ab";
14*7c3d14c8STreehugger Robot   char s2[4] = "abc";
15*7c3d14c8STreehugger Robot   __asan_poison_memory_region ((char *)&s2[2], 2);
16*7c3d14c8STreehugger Robot   r = strcspn(s1, s2);
17*7c3d14c8STreehugger Robot   // CHECK:'s2' <== Memory access at offset {{[0-9]+}} partially overflows this variable
18*7c3d14c8STreehugger Robot   assert(r == 0);
19*7c3d14c8STreehugger Robot   return 0;
20*7c3d14c8STreehugger Robot }
21