[compiler-rt] 7475bd5 - [Msan] Add ptsname, ptsname_r interceptors
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 15:01:02 PDT 2020
Author: Vitaly Buka
Date: 2020-09-30T15:00:52-07:00
New Revision: 7475bd5411a3f62a7860db09a5bcf1fc147c43d6
URL: https://github.com/llvm/llvm-project/commit/7475bd5411a3f62a7860db09a5bcf1fc147c43d6
DIFF: https://github.com/llvm/llvm-project/commit/7475bd5411a3f62a7860db09a5bcf1fc147c43d6.diff
LOG: [Msan] Add ptsname, ptsname_r interceptors
Reviewed By: eugenis, MaskRay
Differential Revision: https://reviews.llvm.org/D88547
Added:
compiler-rt/test/sanitizer_common/TestCases/Linux/ptsname.c
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 80035349b659..4ea35ae368ed 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -4867,6 +4867,34 @@ INTERCEPTOR(char *, tmpnam_r, char *s) {
#define INIT_TMPNAM_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_PTSNAME_R
+INTERCEPTOR(int, ptsname_r, int fd, char *name, SIZE_T namesize) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, ptsname_r, fd, name, namesize);
+ int res = REAL(ptsname_r)(fd, name, namesize);
+ if (res == 0)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, name, REAL(strlen)(name) + 1);
+ return res;
+}
+#define INIT_PTSNAME_R COMMON_INTERCEPT_FUNCTION(ptsname_r);
+#else
+#define INIT_PTSNAME_R
+#endif
+
#if SANITIZER_INTERCEPT_TTYNAME
INTERCEPTOR(char *, ttyname, int fd) {
void *ctx;
@@ -10166,6 +10194,8 @@ static void InitializeCommonInterceptors() {
INIT_PTHREAD_BARRIERATTR_GETPSHARED;
INIT_TMPNAM;
INIT_TMPNAM_R;
+ INIT_PTSNAME;
+ INIT_PTSNAME_R;
INIT_TTYNAME;
INIT_TTYNAME_R;
INIT_TEMPNAM;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index c28ac5513669..c6138e785afe 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -384,6 +384,8 @@
#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_PTSNAME SI_LINUX
+#define SANITIZER_INTERCEPT_PTSNAME_R SI_LINUX
#define SANITIZER_INTERCEPT_TTYNAME SI_POSIX
#define SANITIZER_INTERCEPT_TTYNAME_R SI_POSIX
#define SANITIZER_INTERCEPT_TEMPNAM SI_POSIX
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/ptsname.c b/compiler-rt/test/sanitizer_common/TestCases/Linux/ptsname.c
new file mode 100644
index 000000000000..8fa1d3701296
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/ptsname.c
@@ -0,0 +1,27 @@
+// RUN: %clang %s -o %t && %run %t
+
+#define _GNU_SOURCE
+#define _XOPEN_SOURCE 600
+
+#include <assert.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int main() {
+ int pt = posix_openpt(O_NOCTTY);
+ if (pt == -1)
+ return 0;
+ char *s = ptsname(pt);
+ assert(s);
+ assert(strstr(s, "/dev"));
+
+ char buff[1000] = {};
+ int r = ptsname_r(pt, buff, sizeof(buff));
+ assert(!r);
+ assert(strstr(buff, "/dev"));
+
+ close(pt);
+ return 0;
+}
More information about the llvm-commits
mailing list