summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc71
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h1
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h6
-rw-r--r--compiler-rt/test/sanitizer_common/TestCases/NetBSD/protoent.cc89
4 files changed, 167 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 9121759ba3d..8cd329f1a73 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -6885,6 +6885,76 @@ INTERCEPTOR(int, setttyentpath, char *path) {
#define INIT_TTYENT
#endif
+#if SANITIZER_INTERCEPT_PROTOENT
+INTERCEPTOR(struct __sanitizer_protoent *, getprotoent) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, getprotoent);
+ struct __sanitizer_protoent *p = REAL(getprotoent)();
+ if (p) {
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p, sizeof(*p));
+
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->p_name, REAL(strlen)(p->p_name) + 1);
+
+ SIZE_T pp_size = 1; // One handles the trailing \0
+
+ for (char **pp = p->p_aliases; *pp; ++pp, ++pp_size)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, *pp, REAL(strlen)(*pp) + 1);
+
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->p_aliases,
+ pp_size * sizeof(char **));
+ }
+ return p;
+}
+
+INTERCEPTOR(struct __sanitizer_protoent *, getprotobyname, const char *name) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, getprotobyname, name);
+ if (name)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, name, REAL(strlen)(name) + 1);
+ struct __sanitizer_protoent *p = REAL(getprotobyname)(name);
+ if (p) {
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p, sizeof(*p));
+
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->p_name, REAL(strlen)(p->p_name) + 1);
+
+ SIZE_T pp_size = 1; // One handles the trailing \0
+
+ for (char **pp = p->p_aliases; *pp; ++pp, ++pp_size)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, *pp, REAL(strlen)(*pp) + 1);
+
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->p_aliases,
+ pp_size * sizeof(char **));
+ }
+ return p;
+}
+
+INTERCEPTOR(struct __sanitizer_protoent *, getprotobynumber, int proto) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, getprotobynumber, proto);
+ struct __sanitizer_protoent *p = REAL(getprotobynumber)(proto);
+ if (p) {
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p, sizeof(*p));
+
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->p_name, REAL(strlen)(p->p_name) + 1);
+
+ SIZE_T pp_size = 1; // One handles the trailing \0
+
+ for (char **pp = p->p_aliases; *pp; ++pp, ++pp_size)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, *pp, REAL(strlen)(*pp) + 1);
+
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->p_aliases,
+ pp_size * sizeof(char **));
+ }
+ return p;
+}
+#define INIT_PROTOENT \
+ COMMON_INTERCEPT_FUNCTION(getprotoent); \
+ COMMON_INTERCEPT_FUNCTION(getprotobyname); \
+ COMMON_INTERCEPT_FUNCTION(getprotobynumber)
+#else
+#define INIT_PROTOENT
+#endif
+
static void InitializeCommonInterceptors() {
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -7116,6 +7186,7 @@ static void InitializeCommonInterceptors() {
INIT_FGETLN;
INIT_STRMODE;
INIT_TTYENT;
+ INIT_PROTOENT;
#if SANITIZER_NETBSD
COMMON_INTERCEPT_FUNCTION(__libc_mutex_lock);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 46f381b206a..856109c084e 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -462,5 +462,6 @@
#define SANITIZER_INTERCEPT_FGETLN SI_NETBSD
#define SANITIZER_INTERCEPT_STRMODE SI_NETBSD
#define SANITIZER_INTERCEPT_TTYENT SI_NETBSD
+#define SANITIZER_INTERCEPT_PROTOENT SI_NETBSD
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
index 194f70506d4..0ab37f53cee 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
@@ -113,6 +113,12 @@ struct __sanitizer_shmid_ds {
void *_shm_internal;
};
+struct __sanitizer_protoent {
+ char *p_name;
+ char **p_aliases;
+ int p_proto;
+};
+
extern unsigned struct_msqid_ds_sz;
extern unsigned struct_mq_attr_sz;
extern unsigned struct_timex_sz;
diff --git a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/protoent.cc b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/protoent.cc
new file mode 100644
index 00000000000..c88c6f904a4
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/protoent.cc
@@ -0,0 +1,89 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define STRING_OR_NULL(x) ((x) ? (x) : "null")
+
+void test1() {
+ struct protoent *ptp = getprotoent();
+
+ printf("%s ", STRING_OR_NULL(ptp->p_name));
+
+ for (char **cp = ptp->p_aliases; *cp != NULL; cp++)
+ printf("%s ", STRING_OR_NULL(*cp));
+
+ printf("%d\n", ptp->p_proto);
+ endprotoent();
+}
+
+void test2() {
+ struct protoent *ptp = getprotobyname("icmp");
+
+ printf("%s ", STRING_OR_NULL(ptp->p_name));
+
+ for (char **cp = ptp->p_aliases; *cp != NULL; cp++)
+ printf("%s ", STRING_OR_NULL(*cp));
+
+ printf("%d\n", ptp->p_proto);
+ endprotoent();
+}
+
+void test3() {
+ struct protoent *ptp = getprotobynumber(1);
+
+ printf("%s ", STRING_OR_NULL(ptp->p_name));
+
+ for (char **cp = ptp->p_aliases; *cp != NULL; cp++)
+ printf("%s ", STRING_OR_NULL(*cp));
+
+ printf("%d\n", ptp->p_proto);
+ endprotoent();
+}
+
+void test4() {
+ setprotoent(1);
+ struct protoent *ptp = getprotobynumber(1);
+
+ ptp = getprotobynumber(2);
+
+ printf("%s ", STRING_OR_NULL(ptp->p_name));
+
+ for (char **cp = ptp->p_aliases; *cp != NULL; cp++)
+ printf("%s ", STRING_OR_NULL(*cp));
+
+ printf("%d\n", ptp->p_proto);
+ endprotoent();
+}
+
+void test5() {
+ struct protoent *ptp = getprotobyname("ttp");
+
+ printf("%s ", STRING_OR_NULL(ptp->p_name));
+
+ for (char **cp = ptp->p_aliases; *cp != NULL; cp++)
+ printf("%s ", STRING_OR_NULL(*cp));
+
+ printf("%d\n", ptp->p_proto);
+ endprotoent();
+}
+
+int main(void) {
+ printf("protoent\n");
+
+ test1();
+ test2();
+ test3();
+ test4();
+ test5();
+
+ // CHECK: protoent
+ // CHECK: hopopt HOPOPT 0
+ // CHECK: icmp ICMP 1
+ // CHECK: icmp ICMP 1
+ // CHECK: igmp IGMP 2
+ // CHECK: ttp TTP iptm IPTM 84
+
+ return 0;
+}
OpenPOWER on IntegriCloud