[compiler-rt] r245345 - [msan] Intercept openpty and forkpty.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 13:36:49 PDT 2015


Author: eugenis
Date: Tue Aug 18 15:36:48 2015
New Revision: 245345

URL: http://llvm.org/viewvc/llvm-project?rev=245345&view=rev
Log:
[msan] Intercept openpty and forkpty.

Added:
    compiler-rt/trunk/test/msan/Linux/forkpty.cc
Modified:
    compiler-rt/trunk/lib/msan/msan_interceptors.cc

Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=245345&r1=245344&r2=245345&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Tue Aug 18 15:36:48 2015
@@ -1335,6 +1335,28 @@ INTERCEPTOR(int, fork, void) {
   return pid;
 }
 
+INTERCEPTOR(int, openpty, int *amaster, int *aslave, char *name,
+            const void *termp, const void *winp) {
+  ENSURE_MSAN_INITED();
+  InterceptorScope interceptor_scope;
+  int res = REAL(openpty)(amaster, aslave, name, termp, winp);
+  if (!res) {
+    __msan_unpoison(amaster, sizeof(*amaster));
+    __msan_unpoison(aslave, sizeof(*aslave));
+  }
+  return res;
+}
+
+INTERCEPTOR(int, forkpty, int *amaster, char *name, const void *termp,
+            const void *winp) {
+  ENSURE_MSAN_INITED();
+  InterceptorScope interceptor_scope;
+  int res = REAL(forkpty)(amaster, name, termp, winp);
+  if (res != -1)
+    __msan_unpoison(amaster, sizeof(*amaster));
+  return res;
+}
+
 struct MSanInterceptorContext {
   bool in_interceptor_scope;
 };
@@ -1599,6 +1621,8 @@ void InitializeInterceptors() {
   INTERCEPT_FUNCTION(__cxa_atexit);
   INTERCEPT_FUNCTION(shmat);
   INTERCEPT_FUNCTION(fork);
+  INTERCEPT_FUNCTION(openpty);
+  INTERCEPT_FUNCTION(forkpty);
 
   inited = 1;
 }

Added: compiler-rt/trunk/test/msan/Linux/forkpty.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/Linux/forkpty.cc?rev=245345&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/Linux/forkpty.cc (added)
+++ compiler-rt/trunk/test/msan/Linux/forkpty.cc Tue Aug 18 15:36:48 2015
@@ -0,0 +1,19 @@
+// RUN: %clangxx_msan -O0 -g %s -lutil -o %t && %run %t
+// RUN: %clangxx_msan -O0 -g %s -Wl,-as-needed -lutil -o %t && %run %t
+#include <assert.h>
+#include <pty.h>
+
+#include <sanitizer/msan_interface.h>
+
+int
+main (int argc, char** argv)
+{
+  int master, slave;
+  openpty(&master, &slave, NULL, NULL, NULL);
+  assert(__msan_test_shadow(&master, sizeof(master)) == -1);
+  assert(__msan_test_shadow(&slave, sizeof(slave)) == -1);
+
+  int master2;
+  forkpty(&master2, NULL, NULL, NULL);
+  assert(__msan_test_shadow(&master2, sizeof(master2)) == -1);
+}




More information about the llvm-commits mailing list