[PATCH] D22363: [compiler-rt] Add internal wcslen to avoid crashing on windows 64-bits
Etienne Bergeron via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 14 08:47:29 PDT 2016
etienneb created this revision.
etienneb added a reviewer: rnk.
etienneb added subscribers: llvm-commits, chrisha, wang0109.
Herald added a subscriber: kubabrecka.
The function wcslen is incorrectly hooked on windows 64-bits.
The interception library is not able to hook without breaking the code.
The function is too small and the interception must be done with
trampoline-hooking which turned out to be incorrect on a small
loop (first few instructions have a backedge).
https://reviews.llvm.org/D22363
Files:
lib/asan/asan_win_dll_thunk.cc
lib/sanitizer_common/sanitizer_libc.cc
lib/sanitizer_common/sanitizer_libc.h
Index: lib/sanitizer_common/sanitizer_libc.h
===================================================================
--- lib/sanitizer_common/sanitizer_libc.h
+++ lib/sanitizer_common/sanitizer_libc.h
@@ -51,6 +51,7 @@
uptr internal_strnlen(const char *s, uptr maxlen);
char *internal_strrchr(const char *s, int c);
// This is O(N^2), but we are not using it in hot places.
+uptr internal_wcslen(const wchar_t *s);
char *internal_strstr(const char *haystack, const char *needle);
// Works only for base=10 and doesn't set errno.
s64 internal_simple_strtoll(const char *nptr, char **endptr, int base);
Index: lib/sanitizer_common/sanitizer_libc.cc
===================================================================
--- lib/sanitizer_common/sanitizer_libc.cc
+++ lib/sanitizer_common/sanitizer_libc.cc
@@ -234,6 +234,12 @@
return nullptr;
}
+uptr internal_wcslen(const wchar_t *s) {
+ uptr i = 0;
+ while (s[i]) i++;
+ return i;
+}
+
s64 internal_simple_strtoll(const char *nptr, char **endptr, int base) {
CHECK_EQ(base, 10);
while (IsSpace(*nptr)) nptr++;
Index: lib/asan/asan_win_dll_thunk.cc
===================================================================
--- lib/asan/asan_win_dll_thunk.cc
+++ lib/asan/asan_win_dll_thunk.cc
@@ -379,6 +379,10 @@
INTERCEPT_LIBRARY_FUNCTION(atoi);
INTERCEPT_LIBRARY_FUNCTION(atol);
+
+#ifdef _WIN64
+INTERCEPT_LIBRARY_FUNCTION(__C_specific_handler);
+#else
INTERCEPT_LIBRARY_FUNCTION(_except_handler3);
// _except_handler4 checks -GS cookie which is different for each module, so we
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22363.63985.patch
Type: text/x-patch
Size: 1549 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160714/a4420f5c/attachment.bin>
More information about the llvm-commits
mailing list