2015-05-28 17:24:33 +08:00
|
|
|
// Test needle 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
|
2016-03-11 13:04:49 +08:00
|
|
|
// RUN: %env_asan_opts=intercept_strstr=false:replace_str=false:intercept_strlen=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>
|
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 s1[] = "ab";
|
2015-10-22 16:10:56 +08:00
|
|
|
char s2[4] = "cba";
|
|
|
|
__asan_poison_memory_region ((char *)&s2[2], 2);
|
2015-05-28 17:24:33 +08:00
|
|
|
r = strcasestr(s1, s2);
|
|
|
|
assert(r == 0);
|
2017-03-30 08:41:09 +08:00
|
|
|
// CHECK:'s2'{{.*}} <== Memory access at offset {{[0-9]+}} partially overflows this variable
|
2015-05-28 17:24:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|