[PATCH] D88559: [Sanitizer] Add interceptor for ptsname
Pavel Labath via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 05:21:02 PDT 2020
labath created this revision.
labath added reviewers: vitalybuka, MaskRay.
Herald added a project: Sanitizers.
labath requested review of this revision.
Works the same way as the ttyname interceptor.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D88559
Files:
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/test/msan/Linux/forkpty.cpp
Index: compiler-rt/test/msan/Linux/forkpty.cpp
===================================================================
--- compiler-rt/test/msan/Linux/forkpty.cpp
+++ compiler-rt/test/msan/Linux/forkpty.cpp
@@ -1,9 +1,10 @@
// RUN: %clangxx_msan -O0 -g %s -lutil -o %t && %run %t
#include <assert.h>
+#include <cstring>
#include <pty.h>
+#include <stdlib.h>
#include <unistd.h>
-#include <cstring>
#include <sanitizer/msan_interface.h>
@@ -22,6 +23,10 @@
char *name_p = ttyname(parent);
assert(__msan_test_shadow(name_p, strlen(name_p) + 1) == -1);
+ char *ptsname_p = ptsname(parent);
+ assert(ptsname_p != nullptr);
+ assert(__msan_test_shadow(ptsname_p, strlen(ptsname_p) + 1) == -1);
+
int parent2;
forkpty(&parent2, NULL, NULL, NULL);
assert(__msan_test_shadow(&parent2, sizeof(parent2)) == -1);
Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -386,6 +386,7 @@
#define SANITIZER_INTERCEPT_TMPNAM_R SI_LINUX_NOT_ANDROID || SI_SOLARIS
#define SANITIZER_INTERCEPT_TTYNAME SI_POSIX
#define SANITIZER_INTERCEPT_TTYNAME_R SI_POSIX
+#define SANITIZER_INTERCEPT_PTSNAME SI_POSIX
#define SANITIZER_INTERCEPT_TEMPNAM SI_POSIX
#define SANITIZER_INTERCEPT_SINCOS SI_LINUX || SI_SOLARIS
#define SANITIZER_INTERCEPT_REMQUO SI_POSIX
Index: compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -4895,6 +4895,20 @@
#define INIT_TTYNAME_R
#endif
+#if SANITIZER_INTERCEPT_PTSNAME
+INTERCEPTOR(char *, ptsname, int fd) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, ptsname, fd);
+ char *res = REAL(ptsname)(fd);
+ if (res != nullptr)
+ COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, REAL(strlen)(res) + 1);
+ return res;
+}
+#define INIT_PTSNAME COMMON_INTERCEPT_FUNCTION(ptsname);
+#else
+#define INIT_PTSNAME
+#endif
+
#if SANITIZER_INTERCEPT_TEMPNAM
INTERCEPTOR(char *, tempnam, char *dir, char *pfx) {
void *ctx;
@@ -10168,6 +10182,7 @@
INIT_TMPNAM_R;
INIT_TTYNAME;
INIT_TTYNAME_R;
+ INIT_PTSNAME;
INIT_TEMPNAM;
INIT_PTHREAD_SETNAME_NP;
INIT_PTHREAD_GETNAME_NP;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88559.295249.patch
Type: text/x-patch
Size: 2481 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200930/b053a65d/attachment.bin>
More information about the llvm-commits
mailing list