summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2019-01-11 05:53:09 +0000
committerDavid Carlier <devnexen@gmail.com>2019-01-11 05:53:09 +0000
commit8a81b29215c75b5010c5c68b83d8bd2c99595ba2 (patch)
treef1410c85d266e96ea3a4fea4b56c3ca76dedc00a
parentb97885cc2eb06a29141b6ea67413f8ff17afcc10 (diff)
downloadbcm5719-llvm-8a81b29215c75b5010c5c68b83d8bd2c99595ba2.tar.gz
bcm5719-llvm-8a81b29215c75b5010c5c68b83d8bd2c99595ba2.zip
[Sanitizer] Intercept getusershell
- If entries are properly copied (there were a bug in FreeBSD implementation in earlier version), or list properly reset. Reviewers: vitalybuka, krytarowski Reviewed By: krytarowski Differential Revision: https://reviews.llvm.org/D56562 llvm-svn: 350919
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc16
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h1
-rw-r--r--compiler-rt/test/sanitizer_common/TestCases/Posix/getusershell.cc21
3 files changed, 38 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 252f55552d6..f3ea863bdf4 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9399,6 +9399,21 @@ INTERCEPTOR(char *, fdevname_r, int fd, char *buf, SIZE_T len) {
#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 @@ static void InitializeCommonInterceptors() {
INIT_FUNOPEN;
INIT_FUNOPEN2;
INIT_FDEVNAME;
+ INIT_GETUSERSHELL;
INIT___PRINTF_CHK;
}
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index da51d474100..96fb0b84e08 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/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
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/getusershell.cc b/compiler-rt/test/sanitizer_common/TestCases/Posix/getusershell.cc
new file mode 100644
index 00000000000..6ad1c5bd17a
--- /dev/null
+++ b/compiler-rt/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: '{{.*}}'
+}
OpenPOWER on IntegriCloud