[compiler-rt] r266931 - [asan] Add __strdup interceptor.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 20 15:45:24 PDT 2016
Author: eugenis
Date: Wed Apr 20 17:45:23 2016
New Revision: 266931
URL: http://llvm.org/viewvc/llvm-project?rev=266931&view=rev
Log:
[asan] Add __strdup interceptor.
This happens on Linux when building as C (not C++) with optimization.
Modified:
compiler-rt/trunk/lib/asan/asan_interceptors.cc
compiler-rt/trunk/lib/asan/asan_interceptors.h
compiler-rt/trunk/test/asan/TestCases/strdup_oob_test.cc
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=266931&r1=266930&r2=266931&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Wed Apr 20 17:45:23 2016
@@ -563,6 +563,23 @@ INTERCEPTOR(char*, strdup, const char *s
return reinterpret_cast<char*>(new_mem);
}
+#if ASAN_INTERCEPT___STRDUP
+INTERCEPTOR(char*, __strdup, const char *s) {
+ void *ctx;
+ ASAN_INTERCEPTOR_ENTER(ctx, strdup);
+ if (UNLIKELY(!asan_inited)) return internal_strdup(s);
+ ENSURE_ASAN_INITED();
+ uptr length = REAL(strlen)(s);
+ if (flags()->replace_str) {
+ ASAN_READ_RANGE(ctx, s, length + 1);
+ }
+ GET_STACK_TRACE_MALLOC;
+ void *new_mem = asan_malloc(length + 1, &stack);
+ REAL(memcpy)(new_mem, s, length + 1);
+ return reinterpret_cast<char*>(new_mem);
+}
+#endif // ASAN_INTERCEPT___STRDUP
+
INTERCEPTOR(SIZE_T, wcslen, const wchar_t *s) {
void *ctx;
ASAN_INTERCEPTOR_ENTER(ctx, wcslen);
@@ -719,6 +736,9 @@ void InitializeAsanInterceptors() {
ASAN_INTERCEPT_FUNC(strncat);
ASAN_INTERCEPT_FUNC(strncpy);
ASAN_INTERCEPT_FUNC(strdup);
+#if ASAN_INTERCEPT___STRDUP
+ ASAN_INTERCEPT_FUNC(__strdup);
+#endif
#if ASAN_INTERCEPT_INDEX && ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX
ASAN_INTERCEPT_FUNC(index);
#endif
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.h?rev=266931&r1=266930&r2=266931&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.h (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.h Wed Apr 20 17:45:23 2016
@@ -72,6 +72,12 @@
# define ASAN_INTERCEPT___CXA_ATEXIT 0
#endif
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+# define ASAN_INTERCEPT___STRDUP 1
+#else
+# define ASAN_INTERCEPT___STRDUP 0
+#endif
+
DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size)
DECLARE_REAL(void*, memcpy, void *to, const void *from, uptr size)
DECLARE_REAL(void*, memset, void *block, int c, uptr size)
Modified: compiler-rt/trunk/test/asan/TestCases/strdup_oob_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/strdup_oob_test.cc?rev=266931&r1=266930&r2=266931&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/strdup_oob_test.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/strdup_oob_test.cc Wed Apr 20 17:45:23 2016
@@ -3,6 +3,9 @@
// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// When built as C on Linux, strdup is transformed to __strdup.
+// RUN: %clangxx_asan -O3 -xc %s -o %t && not %run %t 2>&1 | FileCheck %s
+
#include <string.h>
char kString[] = "foo";
@@ -14,7 +17,8 @@ int main(int argc, char **argv) {
// CHECK: #0 {{.*}}main {{.*}}strdup_oob_test.cc:[[@LINE-2]]
// CHECK-LABEL: allocated by thread T{{.*}} here:
// CHECK: #{{[01]}} {{.*}}strdup
+ // CHECK: #{{.*}}main {{.*}}strdup_oob_test.cc:[[@LINE-6]]
// CHECK-LABEL: SUMMARY
- // CHECK: strdup_oob_test.cc:[[@LINE-6]]
+ // CHECK: strdup_oob_test.cc:[[@LINE-7]]
return x;
}
More information about the llvm-commits
mailing list