]> git.proxmox.com Git - rustc.git/blame - src/libcompiler_builtins/compiler-rt/test/asan/TestCases/strstr-1.c
New upstream version 1.28.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / asan / TestCases / strstr-1.c
CommitLineData
92a42be0
SL
1// Test haystack overflow in strstr function
2// RUN: %clang_asan %s -o %t && %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s
3
4// Test intercept_strstr asan option
5// Disable other interceptors because strlen may be called inside strstr
6// RUN: %env_asan_opts=intercept_strstr=false:replace_str=false %run %t 2>&1
7
8#include <assert.h>
9#include <string.h>
10#include <sanitizer/asan_interface.h>
11
12int main(int argc, char **argv) {
13 char *r = 0;
14 char s2[] = "c";
15 char s1[4] = "acb";
16 __asan_poison_memory_region ((char *)&s1[2], 2);
17 r = strstr(s1, s2);
2c00a5a8 18 // CHECK:'s1'{{.*}} <== Memory access at offset {{[0-9]+}} {{partially overflows this variable|is inside this variable}}
92a42be0
SL
19 assert(r == s1 + 1);
20 return 0;
21}