[compiler-rt] r255566 - [msan] Intercept ctermid, ctermid_r.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 14 14:57:50 PST 2015


Author: eugenis
Date: Mon Dec 14 16:57:49 2015
New Revision: 255566

URL: http://llvm.org/viewvc/llvm-project?rev=255566&view=rev
Log:
[msan] Intercept ctermid, ctermid_r.

Added:
    compiler-rt/trunk/test/msan/ctermid.cc
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=255566&r1=255565&r2=255566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Dec 14 16:57:49 2015
@@ -5285,6 +5285,36 @@ INTERCEPTOR(SSIZE_T, process_vm_writev,
 #define INIT_PROCESS_VM_READV
 #endif
 
+#if SANITIZER_INTERCEPT_CTERMID
+INTERCEPTOR(char *, ctermid, char *s) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, ctermid, s);
+  char *res = REAL(ctermid)(s);
+  if (res) {
+    COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, REAL(strlen)(res) + 1);
+  }
+  return res;
+}
+#define INIT_CTERMID COMMON_INTERCEPT_FUNCTION(ctermid);
+#else
+#define INIT_CTERMID
+#endif
+
+#if SANITIZER_INTERCEPT_CTERMID_R
+INTERCEPTOR(char *, ctermid_r, char *s) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, ctermid_r, s);
+  char *res = REAL(ctermid_r)(s);
+  if (res) {
+    COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, REAL(strlen)(res) + 1);
+  }
+  return res;
+}
+#define INIT_CTERMID_R COMMON_INTERCEPT_FUNCTION(ctermid_r);
+#else
+#define INIT_CTERMID_R
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -5459,4 +5489,6 @@ static void InitializeCommonInterceptors
   INIT_PTHREAD_SETCANCEL;
   INIT_MINCORE;
   INIT_PROCESS_VM_READV;
+  INIT_CTERMID;
+  INIT_CTERMID_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=255566&r1=255565&r2=255566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Mon Dec 14 16:57:49 2015
@@ -260,6 +260,8 @@
 #define SANITIZER_INTERCEPT_PTHREAD_SETCANCEL SI_NOT_WINDOWS
 #define SANITIZER_INTERCEPT_MINCORE SI_LINUX
 #define SANITIZER_INTERCEPT_PROCESS_VM_READV SI_LINUX
+#define SANITIZER_INTERCEPT_CTERMID SI_LINUX || SI_MAC || SI_FREEBSD
+#define SANITIZER_INTERCEPT_CTERMID_R SI_MAC || SI_FREEBSD
 
 #define SANITIZER_INTERCEPTOR_HOOKS SI_LINUX
 

Added: compiler-rt/trunk/test/msan/ctermid.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/ctermid.cc?rev=255566&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/ctermid.cc (added)
+++ compiler-rt/trunk/test/msan/ctermid.cc Mon Dec 14 16:57:49 2015
@@ -0,0 +1,13 @@
+// RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t
+
+#include <sanitizer/msan_interface.h>
+#include <stdio.h>
+#include <string.h>
+
+int main(void) {
+  unsigned char s[L_ctermid + 1];
+  char *res = ctermid((char *)s);
+  if (res)
+    printf("%zd\n", strlen(res));
+  return 0;
+}




More information about the llvm-commits mailing list