2015-05-28 17:24:33 +08:00
|
|
|
// Test haystack overflow in strcasestr function
|
2015-06-16 04:43:42 +08:00
|
|
|
// RUN: %clang_asan %s -o %t && ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s
|
2015-05-28 17:24:33 +08:00
|
|
|
|
|
|
|
// Test intercept_strstr asan option
|
2015-06-02 22:59:26 +08:00
|
|
|
// Disable other interceptors because strlen may be called inside strcasestr
|
2015-06-16 04:43:42 +08:00
|
|
|
// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:intercept_strstr=false:replace_str=false %run %t 2>&1
|
2015-05-28 17:24:33 +08:00
|
|
|
|
|
|
|
// There's no interceptor for strcasestr on Windows
|
|
|
|
// XFAIL: win32
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
char *r = 0;
|
|
|
|
char s2[] = "c";
|
2015-06-10 15:16:02 +08:00
|
|
|
char s1[] = {'a', 'C'};
|
2015-05-28 17:24:33 +08:00
|
|
|
char s3 = 0;
|
|
|
|
r = strcasestr(s1, s2);
|
|
|
|
// CHECK:'s{{[1|3]}}' <== Memory access at offset {{[0-9]+ .*}}flows this variable
|
2015-06-10 15:16:02 +08:00
|
|
|
assert(r == s1 + 1);
|
2015-05-28 17:24:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|