[PATCH] Add interceptor for 'textdomain' function

Alexander Taran alextaran at google.com
Mon Dec 2 04:02:31 PST 2013


Hi glider, eugenis,

Add interceptor for function 'textdomain' with test.

http://llvm-reviews.chandlerc.com/D2300

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h
  lib/msan/lit_tests/textdomain.cc

Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -60,6 +60,20 @@
 #define COMMON_INTERCEPTOR_HANDLE_RECVMSG(ctx, msg) ((void)(msg))
 #endif
 
+#if SANITIZER_INTERCEPT_TEXTDOMAIN
+INTERCEPTOR(char*, textdomain, const char *domainname) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, textdomain, domainname);
+  char* domain = REAL(textdomain)(domainname);
+  COMMON_INTERCEPTOR_INITIALIZE_RANGE(ctx, domain,
+     REAL(strlen)(domain) + 1);
+  return domain;
+}
+#define INIT_TEXTDOMAIN COMMON_INTERCEPT_FUNCTION(textdomain)
+#else
+#define INIT_TEXTDOMAIN
+#endif
+
 #if SANITIZER_INTERCEPT_STRCMP
 static inline int CharCmpX(unsigned char c1, unsigned char c2) {
   return (c1 == c2) ? 0 : (c1 < c2) ? -1 : 1;
@@ -2893,6 +2907,7 @@
 #endif
 
 #define SANITIZER_COMMON_INTERCEPTORS_INIT \
+  INIT_TEXTDOMAIN;                         \
   INIT_STRCMP;                             \
   INIT_STRNCMP;                            \
   INIT_STRCASECMP;                         \
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -48,6 +48,7 @@
 #endif
 
 # define SANITIZER_INTERCEPT_STRCMP 1
+# define SANITIZER_INTERCEPT_TEXTDOMAIN 1
 # define SANITIZER_INTERCEPT_STRCASECMP SI_NOT_WINDOWS
 
 # define SANITIZER_INTERCEPT_READ   SI_NOT_WINDOWS
Index: lib/msan/lit_tests/textdomain.cc
===================================================================
--- lib/msan/lit_tests/textdomain.cc
+++ lib/msan/lit_tests/textdomain.cc
@@ -0,0 +1,12 @@
+// RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %t
+
+#include <libintl.h>
+#include <stdio.h>
+
+int main() {
+  const char *td = textdomain("abcd");
+  if (td[0] == 0) {
+    printf("Try read"); 
+  }
+  return 0;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2300.1.patch
Type: text/x-patch
Size: 2061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131202/9e14cbfc/attachment.bin>


More information about the llvm-commits mailing list