diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/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; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/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 diff --git a/compiler-rt/test/msan/Linux/forkpty.cpp b/compiler-rt/test/msan/Linux/forkpty.cpp --- a/compiler-rt/test/msan/Linux/forkpty.cpp +++ b/compiler-rt/test/msan/Linux/forkpty.cpp @@ -1,9 +1,10 @@ // RUN: %clangxx_msan -O0 -g %s -lutil -o %t && %run %t #include +#include #include +#include #include -#include #include @@ -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);