forked from OSchip/llvm-project
asan: Add a wcslen interceptor mirroring strlen
Tested on Linux, since I can't build the tests on Windows yet. llvm-svn: 190022
This commit is contained in:
parent
3af441f1af
commit
0071525492
|
@ -99,6 +99,7 @@ char* strchr(const char *str, int c);
|
||||||
int strcmp(const char *s1, const char* s2);
|
int strcmp(const char *s1, const char* s2);
|
||||||
char* strcpy(char *to, const char* from); // NOLINT
|
char* strcpy(char *to, const char* from); // NOLINT
|
||||||
uptr strlen(const char *s);
|
uptr strlen(const char *s);
|
||||||
|
uptr wcslen(const wchar_t *s);
|
||||||
char* strncat(char *to, const char* from, uptr size);
|
char* strncat(char *to, const char* from, uptr size);
|
||||||
int strncmp(const char *s1, const char* s2, uptr size);
|
int strncmp(const char *s1, const char* s2, uptr size);
|
||||||
char* strncpy(char *to, const char* from, uptr size);
|
char* strncpy(char *to, const char* from, uptr size);
|
||||||
|
|
|
@ -482,6 +482,15 @@ INTERCEPTOR(uptr, strlen, const char *s) {
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INTERCEPTOR(uptr, wcslen, const wchar_t *s) {
|
||||||
|
uptr length = REAL(wcslen)(s);
|
||||||
|
if (!asan_init_is_running) {
|
||||||
|
ENSURE_ASAN_INITED();
|
||||||
|
ASAN_READ_RANGE(s, (length + 1) * sizeof(wchar_t));
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
INTERCEPTOR(char*, strncpy, char *to, const char *from, uptr size) {
|
INTERCEPTOR(char*, strncpy, char *to, const char *from, uptr size) {
|
||||||
ENSURE_ASAN_INITED();
|
ENSURE_ASAN_INITED();
|
||||||
if (flags()->replace_str) {
|
if (flags()->replace_str) {
|
||||||
|
@ -680,6 +689,7 @@ void InitializeAsanInterceptors() {
|
||||||
ASAN_INTERCEPT_FUNC(strchr);
|
ASAN_INTERCEPT_FUNC(strchr);
|
||||||
ASAN_INTERCEPT_FUNC(strcpy); // NOLINT
|
ASAN_INTERCEPT_FUNC(strcpy); // NOLINT
|
||||||
ASAN_INTERCEPT_FUNC(strlen);
|
ASAN_INTERCEPT_FUNC(strlen);
|
||||||
|
ASAN_INTERCEPT_FUNC(wcslen);
|
||||||
ASAN_INTERCEPT_FUNC(strncat);
|
ASAN_INTERCEPT_FUNC(strncat);
|
||||||
ASAN_INTERCEPT_FUNC(strncpy);
|
ASAN_INTERCEPT_FUNC(strncpy);
|
||||||
#if ASAN_INTERCEPT_STRDUP
|
#if ASAN_INTERCEPT_STRDUP
|
||||||
|
|
|
@ -61,6 +61,17 @@ TEST(AddressSanitizer, StrLenOOBTest) {
|
||||||
free(heap_string);
|
free(heap_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(AddressSanitizer, WcsLenTest) {
|
||||||
|
EXPECT_EQ(0, wcslen(Ident(L"")));
|
||||||
|
size_t hello_len = 13;
|
||||||
|
size_t hello_size = (hello_len + 1) * sizeof(wchar_t);
|
||||||
|
EXPECT_EQ(hello_len, wcslen(Ident(L"Hello, World!")));
|
||||||
|
wchar_t *heap_string = Ident((wchar_t*)malloc(hello_size));
|
||||||
|
memcpy(heap_string, L"Hello, World!", hello_size);
|
||||||
|
EXPECT_EQ(hello_len, Ident(wcslen(heap_string)));
|
||||||
|
EXPECT_DEATH(Ident(wcslen(heap_string + 14)), RightOOBReadMessage(0));
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
TEST(AddressSanitizer, StrNLenOOBTest) {
|
TEST(AddressSanitizer, StrNLenOOBTest) {
|
||||||
size_t size = Ident(123);
|
size_t size = Ident(123);
|
||||||
|
|
Loading…
Reference in New Issue