[compiler-rt] r361357 - [Sanitizer] Add interceptor for wcsdup

Pavel Labath via llvm-commits llvm-commits at lists.llvm.org
Wed May 22 01:34:56 PDT 2019


Author: labath
Date: Wed May 22 01:34:56 2019
New Revision: 361357

URL: http://llvm.org/viewvc/llvm-project?rev=361357&view=rev
Log:
[Sanitizer] Add interceptor for wcsdup

Summary: The wide-string equivalent of strdup. Implementation trivial.

Reviewers: vitalybuka, eugenis

Subscribers: kubamracek, delcypher, llvm-commits, #sanitizers

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D62189

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/wcsdup.c
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=361357&r1=361356&r2=361357&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Wed May 22 01:34:56 2019
@@ -6734,6 +6734,23 @@ INTERCEPTOR(wchar_t *, wcsncat, wchar_t
 #define INIT_WCSCAT
 #endif
 
+#if SANITIZER_INTERCEPT_WCSDUP
+INTERCEPTOR(wchar_t *, wcsdup, wchar_t *s) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, wcsdup, s);
+  SIZE_T len = REAL(wcslen)(s);
+  COMMON_INTERCEPTOR_READ_RANGE(ctx, s, sizeof(wchar_t) * (len + 1));
+  wchar_t *result = REAL(wcsdup)(s);
+  if (result)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, result, sizeof(wchar_t) * (len + 1));
+  return result;
+}
+
+#define INIT_WCSDUP COMMON_INTERCEPT_FUNCTION(wcsdup);
+#else
+#define INIT_WCSDUP
+#endif
+
 #if SANITIZER_INTERCEPT_STRXFRM
 static SIZE_T RealStrLen(const char *str) { return REAL(strlen)(str); }
 
@@ -9765,6 +9782,7 @@ static void InitializeCommonInterceptors
   INIT_GETLOADAVG;
   INIT_WCSLEN;
   INIT_WCSCAT;
+  INIT_WCSDUP;
   INIT_WCSXFRM;
   INIT___WCSXFRM_L;
   INIT_ACCT;

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=361357&r1=361356&r2=361357&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Wed May 22 01:34:56 2019
@@ -492,6 +492,7 @@
 #define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_OPENBSD)
 #define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT_WCSCAT SI_POSIX
+#define SANITIZER_INTERCEPT_WCSDUP SI_POSIX
 #define SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION (!SI_WINDOWS && SI_NOT_FUCHSIA)
 #define SANITIZER_INTERCEPT_BSD_SIGNAL SI_ANDROID
 

Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/wcsdup.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/wcsdup.c?rev=361357&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/wcsdup.c (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/wcsdup.c Wed May 22 01:34:56 2019
@@ -0,0 +1,15 @@
+// RUN: %clang %s -o %t && %run %t 2>&1
+
+#include <assert.h>
+#include <stdlib.h>
+#include <wchar.h>
+
+int main(int argc, char **argv) {
+  wchar_t *buff = wcsdup(L"foo");
+  assert(buff[0] == L'f');
+  assert(buff[1] == L'o');
+  assert(buff[2] == L'o');
+  assert(buff[3] == L'\0');
+  free(buff);
+  return 0;
+}




More information about the llvm-commits mailing list