blob: 1cbe6e9bd07c21810045a69264d08c5986429498 [file] [log] [blame]
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07001// Test haystack overflow in strstr function
2// RUN: %clang_asan %s -o %t && ASAN_OPTIONS=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_OPTIONS=$ASAN_OPTIONS:intercept_strstr=false:replace_str=false %run %t 2>&1
7
8#include <assert.h>
9#include <string.h>
10
11int main(int argc, char **argv) {
12 char *r = 0;
13 char s2[] = "c";
14 char s1[] = {'a', 'c'};
15 char s3 = 0;
16 r = strstr(s1, s2);
17 // CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
18 assert(r == s1 + 1);
19 return 0;
20}