summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc17
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h1
-rw-r--r--compiler-rt/test/sanitizer_common/TestCases/NetBSD/fgetln.cc23
3 files changed, 41 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 807d3367efe..45a4b0b4731 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -6807,6 +6807,22 @@ INTERCEPTOR(int, devname_r, u64 dev, u32 type, char *path, uptr len) {
#define INIT_DEVNAME_R
#endif
+#if SANITIZER_INTERCEPT_FGETLN
+INTERCEPTOR(char *, fgetln, __sanitizer_FILE *stream, SIZE_T *len) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, fgetln, stream, len);
+ char *str = REAL(fgetln)(stream, len);
+ if (str && len) {
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, len, sizeof(*len));
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, str, *len);
+ }
+ return str;
+}
+#define INIT_FGETLN COMMON_INTERCEPT_FUNCTION(fgetln)
+#else
+#define INIT_FGETLN
+#endif
+
static void InitializeCommonInterceptors() {
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -7035,6 +7051,7 @@ static void InitializeCommonInterceptors() {
INIT_STRLCPY;
INIT_DEVNAME;
INIT_DEVNAME_R;
+ INIT_FGETLN;
#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 5ccbb315539..022dd59ef8b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -459,5 +459,6 @@
#define SANITIZER_INTERCEPT_DEVNAME SI_NETBSD
#define SANITIZER_INTERCEPT_DEVNAME_R SI_NETBSD
+#define SANITIZER_INTERCEPT_FGETLN SI_NETBSD
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
diff --git a/compiler-rt/test/sanitizer_common/TestCases/NetBSD/fgetln.cc b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/fgetln.cc
new file mode 100644
index 00000000000..2c4f83d4652
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/NetBSD/fgetln.cc
@@ -0,0 +1,23 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(void) {
+ FILE *fp;
+ size_t len;
+ char *s;
+
+ fp = fopen("/etc/hosts", "r");
+ if (!fp)
+ exit(1);
+
+ s = fgetln(fp, &len);
+
+ printf("%.*s\n", (int)len, s);
+
+ if (fclose(fp) == EOF)
+ exit(1);
+
+ return 0;
+}
OpenPOWER on IntegriCloud