blob: a4bc6362636e0b2ac2715261a7bcf8686df5d99d [file] [log] [blame]
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07001// Test needle overflow in strcasestr function
2// RUN: %clang_asan %s -o %t && ASAN_OPTIONS=$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 strcasestr
6// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:intercept_strstr=false:replace_str=false %run %t 2>&1
7
8// There's no interceptor for strcasestr on Windows
9// XFAIL: win32
10
11#define _GNU_SOURCE
12#include <assert.h>
13#include <string.h>
14
15int main(int argc, char **argv) {
16 char *r = 0;
17 char s1[] = "ab";
18 char s2[] = {'c'};
19 char s3 = 0;
20 r = strcasestr(s1, s2);
21 assert(r == 0);
22 // CHECK:'s{{[2|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
23 return 0;
24}