blob: a51fb911e8025304cbd94451969fc0b6dd6cabe5 [file] [log] [blame]
Yury Gribov0ca65fd2015-05-28 09:24:33 +00001// Test stopset overflow in strcspn function
Reid Kleckner85220d02015-08-12 23:50:12 +00002// RUN: %clang_asan %s -o %t && %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s
Yury Gribov0ca65fd2015-05-28 09:24:33 +00003
4// Test intercept_strcspn asan option
Reid Kleckner85220d02015-08-12 23:50:12 +00005// RUN: %env_asan_opts=intercept_strspn=false %run %t 2>&1
Yury Gribov0ca65fd2015-05-28 09:24:33 +00006
7#include <assert.h>
8#include <string.h>
Yury Gribov8da14082015-10-22 08:10:56 +00009#include <sanitizer/asan_interface.h>
Yury Gribov0ca65fd2015-05-28 09:24:33 +000010
11int main(int argc, char **argv) {
12 size_t r;
13 char s1[] = "ab";
Yury Gribov8da14082015-10-22 08:10:56 +000014 char s2[4] = "abc";
15 __asan_poison_memory_region ((char *)&s2[2], 2);
Yury Gribov0ca65fd2015-05-28 09:24:33 +000016 r = strcspn(s1, s2);
Kuba Mracek8ed29282017-03-30 00:41:09 +000017 // CHECK:'s2'{{.*}} <== Memory access at offset {{[0-9]+}} partially overflows this variable
Yury Gribovef40f0b2015-06-10 07:16:02 +000018 assert(r == 0);
Yury Gribov0ca65fd2015-05-28 09:24:33 +000019 return 0;
20}