[compiler-rt] r185338 - [sanitizer] Intercept getnameinfo.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Mon Jul 1 06:51:32 PDT 2013


Author: eugenis
Date: Mon Jul  1 08:51:31 2013
New Revision: 185338

URL: http://llvm.org/viewvc/llvm-project?rev=185338&view=rev
Log:
[sanitizer] Intercept getnameinfo.

Modified:
    compiler-rt/trunk/lib/msan/tests/msan_test.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h

Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=185338&r1=185337&r2=185338&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Mon Jul  1 08:51:31 2013
@@ -754,6 +754,25 @@ TEST(MemorySanitizer, getaddrinfo) {
   EXPECT_NOT_POISONED(*(sockaddr_in*)ai->ai_addr); 
 }
 
+TEST(MemorySanitizer, getnameinfo) {
+  struct sockaddr_in sai;
+  sai.sin_family = AF_INET;
+  sai.sin_port = 80;
+  sai.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+  char host[500];
+  char serv[500];
+  int res = getnameinfo((struct sockaddr *)&sai, sizeof(sai), host,
+                        sizeof(host), serv, sizeof(serv), 0);
+  ASSERT_EQ(0, res);
+  EXPECT_NOT_POISONED(host[0]);
+  EXPECT_POISONED(host[sizeof(host) - 1]);
+
+  ASSERT_NE(0, strlen(host));
+  EXPECT_NOT_POISONED(serv[0]);
+  EXPECT_POISONED(serv[sizeof(serv) - 1]);
+  ASSERT_NE(0, strlen(serv));
+}
+
 #define EXPECT_HOSTENT_NOT_POISONED(he)        \
   do {                                         \
     EXPECT_NOT_POISONED(*(he));                \

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=185338&r1=185337&r2=185338&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Jul  1 08:51:31 2013
@@ -943,6 +943,29 @@ INTERCEPTOR(int, getaddrinfo, char *node
 #define INIT_GETADDRINFO
 #endif
 
+#if SANITIZER_INTERCEPT_GETNAMEINFO
+INTERCEPTOR(int, getnameinfo, void *sockaddr, unsigned salen, char *host,
+            unsigned hostlen, char *serv, unsigned servlen, int flags) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, getnameinfo, sockaddr, salen, host, hostlen,
+                           serv, servlen, flags);
+  // FIXME: consider adding READ_RANGE(sockaddr, salen)
+  // There is padding in in_addr that may make this too noisy
+  int res =
+      REAL(getnameinfo)(sockaddr, salen, host, hostlen, serv, servlen, flags);
+  if (res == 0) {
+    if (host && hostlen)
+      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, host, REAL(strlen)(host) + 1);
+    if (serv && servlen)
+      COMMON_INTERCEPTOR_WRITE_RANGE(ctx, serv, REAL(strlen)(serv) + 1);
+  }
+  return res;
+}
+#define INIT_GETNAMEINFO INTERCEPT_FUNCTION(getnameinfo);
+#else
+#define INIT_GETNAMEINFO
+#endif
+
 #if SANITIZER_INTERCEPT_GETSOCKNAME
 INTERCEPTOR(int, getsockname, int sock_fd, void *addr, int *addrlen) {
   void *ctx;
@@ -1407,6 +1430,7 @@ INTERCEPTOR(uptr, ptrace, int request, i
   INIT_INET;                               \
   INIT_PTHREAD_GETSCHEDPARAM;              \
   INIT_GETADDRINFO;                        \
+  INIT_GETNAMEINFO;                        \
   INIT_GETSOCKNAME;                        \
   INIT_GETHOSTBYNAME;                      \
   INIT_GETHOSTBYNAME_R;                    \

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=185338&r1=185337&r2=185338&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Mon Jul  1 08:51:31 2013
@@ -80,6 +80,7 @@
 # define SANITIZER_INTERCEPT_INET SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_PTHREAD_GETSCHEDPARAM SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_GETADDRINFO SI_NOT_WINDOWS
+# define SANITIZER_INTERCEPT_GETNAMEINFO SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_GETSOCKNAME SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_GETHOSTBYNAME SI_NOT_WINDOWS
 # define SANITIZER_INTERCEPT_GETHOSTBYNAME_R SI_LINUX

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc?rev=185338&r1=185337&r2=185338&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Mon Jul  1 08:51:31 2013
@@ -315,6 +315,7 @@ void StatOutput(u64 *stat) {
   name[StatInt_inet_pton]                = "  inet_pton                       ";
   name[StatInt_inet_aton]                = "  inet_aton                       ";
   name[StatInt_getaddrinfo]              = "  getaddrinfo                     ";
+  name[StatInt_getnameinfo]              = "  getnameinfo                     ";
   name[StatInt_getsockname]              = "  getsockname                     ";
   name[StatInt_gethostent]               = "  gethostent                      ";
   name[StatInt_gethostbyname]            = "  gethostbyname                   ";

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h?rev=185338&r1=185337&r2=185338&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Mon Jul  1 08:51:31 2013
@@ -310,6 +310,7 @@ enum StatType {
   StatInt_inet_pton,
   StatInt_inet_aton,
   StatInt_getaddrinfo,
+  StatInt_getnameinfo,
   StatInt_getsockname,
   StatInt_gethostent,
   StatInt_gethostbyname,





More information about the llvm-commits mailing list