[compiler-rt] r355214 - [msan] Add an interceptor for ttyname().
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 1 10:22:44 PST 2019
Author: eugenis
Date: Fri Mar 1 10:22:44 2019
New Revision: 355214
URL: http://llvm.org/viewvc/llvm-project?rev=355214&view=rev
Log:
[msan] Add an interceptor for ttyname().
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/trunk/test/msan/Linux/forkpty.cc
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=355214&r1=355213&r2=355214&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Fri Mar 1 10:22:44 2019
@@ -4738,6 +4738,20 @@ INTERCEPTOR(char *, tmpnam_r, char *s) {
#define INIT_TMPNAM_R
#endif
+#if SANITIZER_INTERCEPT_TTYNAME
+INTERCEPTOR(char *, ttyname, int fd) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, ttyname, fd);
+ char *res = REAL(ttyname)(fd);
+ if (res != nullptr)
+ COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, REAL(strlen)(res) + 1);
+ return res;
+}
+#define INIT_TTYNAME COMMON_INTERCEPT_FUNCTION(ttyname);
+#else
+#define INIT_TTYNAME
+#endif
+
#if SANITIZER_INTERCEPT_TTYNAME_R
INTERCEPTOR(int, ttyname_r, int fd, char *name, SIZE_T namesize) {
void *ctx;
@@ -9653,6 +9667,7 @@ static void InitializeCommonInterceptors
INIT_PTHREAD_BARRIERATTR_GETPSHARED;
INIT_TMPNAM;
INIT_TMPNAM_R;
+ INIT_TTYNAME;
INIT_TTYNAME_R;
INIT_TEMPNAM;
INIT_PTHREAD_SETNAME_NP;
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=355214&r1=355213&r2=355214&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Fri Mar 1 10:22:44 2019
@@ -360,6 +360,7 @@
#define SANITIZER_INTERCEPT_THR_EXIT SI_FREEBSD
#define SANITIZER_INTERCEPT_TMPNAM SI_POSIX
#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_TEMPNAM SI_POSIX
#define SANITIZER_INTERCEPT_SINCOS SI_LINUX || SI_SOLARIS
Modified: compiler-rt/trunk/test/msan/Linux/forkpty.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/Linux/forkpty.cc?rev=355214&r1=355213&r2=355214&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/Linux/forkpty.cc (original)
+++ compiler-rt/trunk/test/msan/Linux/forkpty.cc Fri Mar 1 10:22:44 2019
@@ -15,9 +15,12 @@ main (int argc, char** argv)
assert(__msan_test_shadow(&master, sizeof(master)) == -1);
assert(__msan_test_shadow(&slave, sizeof(slave)) == -1);
- char ttyname[255];
- ttyname_r(master, ttyname, sizeof(ttyname));
- assert(__msan_test_shadow(ttyname, strlen(ttyname) + 1) == -1);
+ char name[255];
+ ttyname_r(master, name, sizeof(name));
+ assert(__msan_test_shadow(name, strlen(name) + 1) == -1);
+
+ char *name_p = ttyname(master);
+ assert(__msan_test_shadow(name_p, strlen(name_p) + 1) == -1);
int master2;
forkpty(&master2, NULL, NULL, NULL);
More information about the llvm-commits
mailing list