2015-05-28 17:24:33 +08:00
|
|
|
// Test haystack overflow in strcasestr function
|
2015-08-13 07:50:12 +08:00
|
|
|
// RUN: %clang_asan %s -o %t && %env_asan_opts=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-08-13 07:50:12 +08:00
|
|
|
// RUN: %env_asan_opts=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
|
2018-08-09 10:16:18 +08:00
|
|
|
// XFAIL: windows-msvc
|
2015-05-28 17:24:33 +08:00
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
2015-10-22 16:10:56 +08:00
|
|
|
#include <sanitizer/asan_interface.h>
|
2015-05-28 17:24:33 +08:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
char *r = 0;
|
|
|
|
char s2[] = "c";
|
2015-10-22 16:10:56 +08:00
|
|
|
char s1[4] = "abC";
|
|
|
|
__asan_poison_memory_region ((char *)&s1[2], 2);
|
2015-05-28 17:24:33 +08:00
|
|
|
r = strcasestr(s1, s2);
|
2017-03-30 08:41:09 +08:00
|
|
|
// CHECK:'s1'{{.*}} <== Memory access at offset {{[0-9]+}} partially overflows this variable
|
2015-10-22 16:10:56 +08:00
|
|
|
assert(r == s1 + 2);
|
2015-05-28 17:24:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|