[compiler-rt] 3675e14 - [Sanitizers] intercept ttyent api on FreeBSD.
David Carlier via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 23 20:27:21 PDT 2021
Author: David Carlier
Date: 2021-09-24T04:26:05+01:00
New Revision: 3675e147a1ccbce44ce64a1bc8dd38547aba1443
URL: https://github.com/llvm/llvm-project/commit/3675e147a1ccbce44ce64a1bc8dd38547aba1443
DIFF: https://github.com/llvm/llvm-project/commit/3675e147a1ccbce44ce64a1bc8dd38547aba1443.diff
LOG: [Sanitizers] intercept ttyent api on FreeBSD.
and ttyentpath separately on NetBSD.
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D109843
Added:
compiler-rt/test/sanitizer_common/TestCases/Linux/ttyent.cpp
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
Removed:
compiler-rt/test/sanitizer_common/TestCases/NetBSD/ttyent.cpp
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 5e731ac399102..9511a3b19a0f7 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7543,6 +7543,14 @@ INTERCEPTOR(struct __sanitizer_ttyent *, getttynam, char *name) {
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ttyent, struct_ttyent_sz);
return ttyent;
}
+#define INIT_TTYENT \
+ COMMON_INTERCEPT_FUNCTION(getttyent); \
+ COMMON_INTERCEPT_FUNCTION(getttynam);
+#else
+#define INIT_TTYENT
+#endif
+
+#if SANITIZER_INTERCEPT_TTYENTPATH
INTERCEPTOR(int, setttyentpath, char *path) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, setttyentpath, path);
@@ -7550,12 +7558,9 @@ INTERCEPTOR(int, setttyentpath, char *path) {
COMMON_INTERCEPTOR_READ_RANGE(ctx, path, internal_strlen(path) + 1);
return REAL(setttyentpath)(path);
}
-#define INIT_TTYENT \
- COMMON_INTERCEPT_FUNCTION(getttyent); \
- COMMON_INTERCEPT_FUNCTION(getttynam); \
- COMMON_INTERCEPT_FUNCTION(setttyentpath)
+#define INIT_TTYENTPATH COMMON_INTERCEPT_FUNCTION(setttyentpath);
#else
-#define INIT_TTYENT
+#define INIT_TTYENTPATH
#endif
#if SANITIZER_INTERCEPT_PROTOENT
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index ee683da3edc81..02c51d9fb0d24 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -521,7 +521,8 @@
#define SANITIZER_INTERCEPT_DEVNAME_R (SI_NETBSD || SI_FREEBSD)
#define SANITIZER_INTERCEPT_FGETLN (SI_NETBSD || SI_FREEBSD)
#define SANITIZER_INTERCEPT_STRMODE (SI_NETBSD || SI_FREEBSD)
-#define SANITIZER_INTERCEPT_TTYENT SI_NETBSD
+#define SANITIZER_INTERCEPT_TTYENT (SI_NETBSD || SI_FREEBSD)
+#define SANITIZER_INTERCEPT_TTYENTPATH SI_NETBSD
#define SANITIZER_INTERCEPT_PROTOENT (SI_LINUX || SI_NETBSD || SI_FREEBSD)
#define SANITIZER_INTERCEPT_PROTOENT_R SI_GLIBC
#define SANITIZER_INTERCEPT_NETENT (SI_LINUX || SI_NETBSD || SI_FREEBSD)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
index 042ebde3789d3..bfe3eea464d64 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
@@ -74,6 +74,7 @@
#include <term.h>
#include <termios.h>
#include <time.h>
+#include <ttyent.h>
#include <utime.h>
#include <utmpx.h>
#include <vis.h>
@@ -174,6 +175,8 @@ const int wordexp_wrde_dooffs = WRDE_DOOFFS;
unsigned path_max = PATH_MAX;
+int struct_ttyent_sz = sizeof(struct ttyent);
+
// ioctl arguments
unsigned struct_ifreq_sz = sizeof(struct ifreq);
unsigned struct_termios_sz = sizeof(struct termios);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
index e8c3f1a85a557..89022ca6422c9 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
@@ -383,6 +383,8 @@ extern const int wordexp_wrde_dooffs;
extern unsigned path_max;
+extern int struct_ttyent_sz;
+
struct __sanitizer_wordexp_t {
uptr we_wordc;
char **we_wordv;
@@ -412,6 +414,16 @@ struct __sanitizer_ifconf {
} ifc_ifcu;
};
+struct __sanitizer__ttyent {
+ char *ty_name;
+ char *ty_getty;
+ char *ty_type;
+ int ty_status;
+ char *ty_window;
+ char *ty_comment;
+ char *ty_group;
+};
+
# define IOC_NRBITS 8
# define IOC_TYPEBITS 8
# if defined(__powerpc__) || defined(__powerpc64__) || defined(__mips__)
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/ttyent.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/ttyent.cpp
new file mode 100644
index 0000000000000..681f511b330bd
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/ttyent.cpp
@@ -0,0 +1,60 @@
+// RUN: %clangxx -O0 -g %s -o %t
+//
+// REQUIRES: freebsd, netbsd
+
+#include <assert.h>
+#include <stdlib.h>
+#include <ttyent.h>
+
+#include <assert.h>
+#include <stdlib.h>
+#include <ttyent.h>
+
+void test1() {
+ struct ttyent *typ = getttyent();
+ assert(typ && typ->ty_name != nullptr);
+ assert(typ->ty_type != nullptr);
+ endttyent();
+}
+
+void test2() {
+ struct ttyent *typ = getttynam("console");
+ assert(typ && typ->ty_name != nullptr);
+ assert(typ->ty_type != nullptr);
+ endttyent();
+}
+
+void test3() {
+ if (!setttyent())
+ exit(1);
+
+ struct ttyent *typ = getttyent();
+ assert(typ && typ->ty_name != nullptr);
+ assert(typ->ty_type != nullptr);
+ endttyent();
+}
+
+#if defined(__NetBSD__)
+void test4() {
+ if (!setttyentpath(_PATH_TTYS))
+ exit(1);
+
+ struct ttyent *typ = getttyent();
+ assert(typ && typ->ty_name != nullptr);
+ assert(typ->ty_type != nullptr);
+ assert(typ->ty_class != nullptr);
+
+ endttyent();
+}
+#endif
+
+int main(void) {
+ test1();
+ test2();
+ test3();
+#if defined(__NetBSD__)
+ test4();
+#endif
+
+ return 0;
+}
diff --git a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/ttyent.cpp b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/ttyent.cpp
deleted file mode 100644
index 73bc0a5da56b5..0000000000000
--- a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/ttyent.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <ttyent.h>
-
-#define STRING_OR_NULL(x) ((x) ? (x) : "null")
-
-void test1() {
- struct ttyent *typ = getttyent();
-
- printf("%s %s %s %d %s %s %s\n", STRING_OR_NULL(typ->ty_name),
- STRING_OR_NULL(typ->ty_getty), STRING_OR_NULL(typ->ty_type),
- typ->ty_status, STRING_OR_NULL(typ->ty_window),
- STRING_OR_NULL(typ->ty_comment), STRING_OR_NULL(typ->ty_class));
-
- endttyent();
-}
-
-void test2() {
- struct ttyent *typ = getttynam("console");
-
- printf("%s %s %s %d %s %s %s\n", STRING_OR_NULL(typ->ty_name),
- STRING_OR_NULL(typ->ty_getty), STRING_OR_NULL(typ->ty_type),
- typ->ty_status, STRING_OR_NULL(typ->ty_window),
- STRING_OR_NULL(typ->ty_comment), STRING_OR_NULL(typ->ty_class));
-
- endttyent();
-}
-
-void test3() {
- if (!setttyent())
- exit(1);
-
- struct ttyent *typ = getttyent();
-
- printf("%s %s %s %d %s %s %s\n", STRING_OR_NULL(typ->ty_name),
- STRING_OR_NULL(typ->ty_getty), STRING_OR_NULL(typ->ty_type),
- typ->ty_status, STRING_OR_NULL(typ->ty_window),
- STRING_OR_NULL(typ->ty_comment), STRING_OR_NULL(typ->ty_class));
-
- endttyent();
-}
-
-void test4() {
- if (!setttyentpath(_PATH_TTYS))
- exit(1);
-
- struct ttyent *typ = getttyent();
-
- printf("%s %s %s %d %s %s %s\n", STRING_OR_NULL(typ->ty_name),
- STRING_OR_NULL(typ->ty_getty), STRING_OR_NULL(typ->ty_type),
- typ->ty_status, STRING_OR_NULL(typ->ty_window),
- STRING_OR_NULL(typ->ty_comment), STRING_OR_NULL(typ->ty_class));
-
- endttyent();
-}
-
-int main(void) {
- printf("ttyent\n");
-
- test1();
- test2();
- test3();
- test4();
-
- // CHECK: ttyent
-
- return 0;
-}
More information about the llvm-commits
mailing list