[compiler-rt] r281116 - [sanitizer] Add interceptor for ttyname_r
Keno Fischer via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 9 16:09:34 PDT 2016
Author: kfischer
Date: Fri Sep 9 18:09:34 2016
New Revision: 281116
URL: http://llvm.org/viewvc/llvm-project?rev=281116&view=rev
Log:
[sanitizer] Add interceptor for ttyname_r
Reviewers: eugenis
Subscribers: kubabrecka, llvm-commits
Differential Revision: https://reviews.llvm.org/D24375
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=281116&r1=281115&r2=281116&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Fri Sep 9 18:09:34 2016
@@ -4183,6 +4183,20 @@ INTERCEPTOR(char *, tmpnam_r, char *s) {
#define INIT_TMPNAM_R
#endif
+#if SANITIZER_INTERCEPT_TTYNAME_R
+INTERCEPTOR(int, ttyname_r, int fd, char *name, SIZE_T namesize) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, ttyname_r, fd, name, namesize);
+ int res = REAL(ttyname_r)(fd, name, namesize);
+ if (res == 0)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, name, REAL(strlen)(name) + 1);
+ return res;
+}
+#define INIT_TTYNAME_R COMMON_INTERCEPT_FUNCTION(ttyname_r);
+#else
+#define INIT_TTYNAME_R
+#endif
+
#if SANITIZER_INTERCEPT_TEMPNAM
INTERCEPTOR(char *, tempnam, char *dir, char *pfx) {
void *ctx;
@@ -6008,6 +6022,7 @@ static void InitializeCommonInterceptors
INIT_PTHREAD_BARRIERATTR_GETPSHARED;
INIT_TMPNAM;
INIT_TMPNAM_R;
+ INIT_TTYNAME_R;
INIT_TEMPNAM;
INIT_PTHREAD_SETNAME_NP;
INIT_SINCOS;
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=281116&r1=281115&r2=281116&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Fri Sep 9 18:09:34 2016
@@ -235,6 +235,7 @@
#define SANITIZER_INTERCEPT_PTHREAD_BARRIERATTR_GETPSHARED SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT_TMPNAM SI_NOT_WINDOWS
#define SANITIZER_INTERCEPT_TMPNAM_R SI_LINUX_NOT_ANDROID
+#define SANITIZER_INTERCEPT_TTYNAME_R SI_NOT_WINDOWS
#define SANITIZER_INTERCEPT_TEMPNAM SI_NOT_WINDOWS
#define SANITIZER_INTERCEPT_SINCOS SI_LINUX
#define SANITIZER_INTERCEPT_REMQUO SI_NOT_WINDOWS
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=281116&r1=281115&r2=281116&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/Linux/forkpty.cc (original)
+++ compiler-rt/trunk/test/msan/Linux/forkpty.cc Fri Sep 9 18:09:34 2016
@@ -2,6 +2,8 @@
#include <assert.h>
#include <pty.h>
+#include <unistd.h>
+#include <cstring>
#include <sanitizer/msan_interface.h>
@@ -13,6 +15,10 @@ 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);
+
int master2;
forkpty(&master2, NULL, NULL, NULL);
assert(__msan_test_shadow(&master2, sizeof(master2)) == -1);
More information about the llvm-commits
mailing list