[PATCH] D56562: [Sanitizer] Intercept getusershell

David CARLIER via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 10 21:57:21 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL350919: [Sanitizer] Intercept getusershell (authored by devnexen, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D56562?vs=181164&id=181210#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56562/new/

https://reviews.llvm.org/D56562

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
  compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getusershell.cc


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -548,6 +548,7 @@
 #define SANITIZER_INTERCEPT_GETFSENT (SI_FREEBSD || SI_NETBSD || SI_MAC)
 #define SANITIZER_INTERCEPT_ARC4RANDOM (SI_FREEBSD || SI_NETBSD)
 #define SANITIZER_INTERCEPT_FDEVNAME SI_FREEBSD
+#define SANITIZER_INTERCEPT_GETUSERSHELL SI_POSIX
 
 #define SANITIZER_INTERCEPT_POPEN SI_POSIX
 #define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9399,6 +9399,21 @@
 #define INIT_FDEVNAME
 #endif
 
+#if SANITIZER_INTERCEPT_GETUSERSHELL
+INTERCEPTOR(char *, getusershell) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, getusershell);
+  char *res = REAL(getusershell)();
+  if (res)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, res, REAL(strlen)(res) + 1);
+  return res;
+}
+
+#define INIT_GETUSERSHELL COMMON_INTERCEPT_FUNCTION(getusershell);
+#else
+#define INIT_GETUSERSHELL
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map =
@@ -9687,6 +9702,7 @@
   INIT_FUNOPEN;
   INIT_FUNOPEN2;
   INIT_FDEVNAME;
+  INIT_GETUSERSHELL;
 
   INIT___PRINTF_CHK;
 }
Index: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getusershell.cc
===================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getusershell.cc
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getusershell.cc
@@ -0,0 +1,21 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int main(void) {
+  printf("getusershell\n");
+
+  setusershell();
+  char *fentry = getusershell();
+
+  printf("First entry: '%s'\n", fentry);
+
+  endusershell();
+
+  return 0;
+  // CHECK: getusershell
+  // CHECK: First entry: '{{.*}}'
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56562.181210.patch
Type: text/x-patch
Size: 2385 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190111/4baa17fb/attachment.bin>


More information about the llvm-commits mailing list