[PATCH] D43482: Add new interceptor: fgetln(3)

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 07:55:10 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT325587: Add new interceptor: fgetln(3) (authored by kamil, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43482?vs=134969&id=135065#toc

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D43482

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h
  test/sanitizer_common/TestCases/NetBSD/fgetln.cc


Index: test/sanitizer_common/TestCases/NetBSD/fgetln.cc
===================================================================
--- test/sanitizer_common/TestCases/NetBSD/fgetln.cc
+++ 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;
+}
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ 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
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -6807,6 +6807,22 @@
 #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 @@
   INIT_STRLCPY;
   INIT_DEVNAME;
   INIT_DEVNAME_R;
+  INIT_FGETLN;
 
 #if SANITIZER_NETBSD
   COMMON_INTERCEPT_FUNCTION(__libc_mutex_lock);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43482.135065.patch
Type: text/x-patch
Size: 2174 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180220/651c0a64/attachment.bin>


More information about the llvm-commits mailing list