[compiler-rt] r212937 - [sanitizer] Intercept getpass.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Mon Jul 14 06:07:51 PDT 2014


Author: eugenis
Date: Mon Jul 14 08:07:51 2014
New Revision: 212937

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

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/getpass.cc   (with props)
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=212937&r1=212936&r2=212937&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 14 08:07:51 2014
@@ -4628,6 +4628,22 @@ INTERCEPTOR(int, dlclose, void *handle)
 #define INIT_DLOPEN_DLCLOSE
 #endif
 
+#if SANITIZER_INTERCEPT_GETPASS
+INTERCEPTOR(char *, getpass, const char *prompt) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, getpass, prompt);
+  if (prompt)
+    COMMON_INTERCEPTOR_READ_RANGE(ctx, prompt, REAL(strlen)(prompt)+1);
+  char *res = REAL(getpass)(prompt);
+  if (res) COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, REAL(strlen)(res)+1);
+  return res;
+}
+
+#define INIT_GETPASS COMMON_INTERCEPT_FUNCTION(getpass);
+#else
+#define INIT_GETPASS
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -4786,4 +4802,5 @@ static void InitializeCommonInterceptors
   INIT_FFLUSH;
   INIT_FCLOSE;
   INIT_DLOPEN_DLCLOSE;
+  INIT_GETPASS;
 }

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=212937&r1=212936&r2=212937&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 14 08:07:51 2014
@@ -222,5 +222,6 @@
 #define SANITIZER_INTERCEPT_FFLUSH SI_NOT_WINDOWS
 #define SANITIZER_INTERCEPT_FCLOSE SI_NOT_WINDOWS
 #define SANITIZER_INTERCEPT_DLOPEN_DLCLOSE SI_LINUX_NOT_ANDROID || SI_MAC
+#define SANITIZER_INTERCEPT_GETPASS SI_LINUX_NOT_ANDROID || SI_MAC
 
 #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H

Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/getpass.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/getpass.cc?rev=212937&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/getpass.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/getpass.cc Mon Jul 14 08:07:51 2014
@@ -0,0 +1,33 @@
+// RUN: %clangxx -O0 -g %s -lutil -o %t && %run %t | FileCheck %s
+#include <assert.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <pty.h>
+
+int
+main (int argc, char** argv)
+{
+    int master;
+    int pid = forkpty(&master, NULL, NULL, NULL);
+
+    if(pid == -1) {
+      fprintf(stderr, "forkpty failed\n");
+      return 1;
+    } else if (pid > 0) {
+      char buf[1024];
+      int res = read(master, buf, sizeof(buf));
+      write(1, buf, res);
+      write(master, "password\n", 9);
+      res = read(master, buf, sizeof(buf));
+      write(1, buf, res);
+    } else {
+      char *s = getpass("prompt");
+      assert(strcmp(s, "password") == 0);
+      write(1, "done\n", 5);
+    }
+    return 0;
+}
+
+// CHECK: prompt
+// CHECK: done

Propchange: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/getpass.cc
------------------------------------------------------------------------------
    svn:eol-style = LF





More information about the llvm-commits mailing list