summaryrefslogtreecommitdiffstats
path: root/compiler-rt
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2013-09-05 01:13:49 +0000
committerReid Kleckner <reid@kleckner.net>2013-09-05 01:13:49 +0000
commit0071525492b6876ddf2a2920d5295f697def85cf (patch)
tree501d034291938d542c4578298bd411a37f5dd61d /compiler-rt
parent3af441f1afc94783a6e4fb9d58bc4514c5f6aecc (diff)
downloadbcm5719-llvm-0071525492b6876ddf2a2920d5295f697def85cf.tar.gz
bcm5719-llvm-0071525492b6876ddf2a2920d5295f697def85cf.zip
asan: Add a wcslen interceptor mirroring strlen
Tested on Linux, since I can't build the tests on Windows yet. llvm-svn: 190022
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/asan/asan_intercepted_functions.h1
-rw-r--r--compiler-rt/lib/asan/asan_interceptors.cc10
-rw-r--r--compiler-rt/lib/asan/tests/asan_str_test.cc11
3 files changed, 22 insertions, 0 deletions
diff --git a/compiler-rt/lib/asan/asan_intercepted_functions.h b/compiler-rt/lib/asan/asan_intercepted_functions.h
index 842781cdb17..7b19b3dad90 100644
--- a/compiler-rt/lib/asan/asan_intercepted_functions.h
+++ b/compiler-rt/lib/asan/asan_intercepted_functions.h
@@ -99,6 +99,7 @@ char* strchr(const char *str, int c);
int strcmp(const char *s1, const char* s2);
char* strcpy(char *to, const char* from); // NOLINT
uptr strlen(const char *s);
+uptr wcslen(const wchar_t *s);
char* strncat(char *to, const char* from, uptr size);
int strncmp(const char *s1, const char* s2, uptr size);
char* strncpy(char *to, const char* from, uptr size);
diff --git a/compiler-rt/lib/asan/asan_interceptors.cc b/compiler-rt/lib/asan/asan_interceptors.cc
index d7b43da08fe..c996b66135b 100644
--- a/compiler-rt/lib/asan/asan_interceptors.cc
+++ b/compiler-rt/lib/asan/asan_interceptors.cc
@@ -482,6 +482,15 @@ INTERCEPTOR(uptr, strlen, const char *s) {
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) {
ENSURE_ASAN_INITED();
if (flags()->replace_str) {
@@ -680,6 +689,7 @@ void InitializeAsanInterceptors() {
ASAN_INTERCEPT_FUNC(strchr);
ASAN_INTERCEPT_FUNC(strcpy); // NOLINT
ASAN_INTERCEPT_FUNC(strlen);
+ ASAN_INTERCEPT_FUNC(wcslen);
ASAN_INTERCEPT_FUNC(strncat);
ASAN_INTERCEPT_FUNC(strncpy);
#if ASAN_INTERCEPT_STRDUP
diff --git a/compiler-rt/lib/asan/tests/asan_str_test.cc b/compiler-rt/lib/asan/tests/asan_str_test.cc
index 128fb61c25a..34be0b50cf8 100644
--- a/compiler-rt/lib/asan/tests/asan_str_test.cc
+++ b/compiler-rt/lib/asan/tests/asan_str_test.cc
@@ -61,6 +61,17 @@ TEST(AddressSanitizer, StrLenOOBTest) {
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__
TEST(AddressSanitizer, StrNLenOOBTest) {
size_t size = Ident(123);
OpenPOWER on IntegriCloud