[compiler-rt] r325199 - Add new interceptor: lstat(2)

Kamil Rytarowski via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 14 18:17:06 PST 2018


Author: kamil
Date: Wed Feb 14 18:17:06 2018
New Revision: 325199

URL: http://llvm.org/viewvc/llvm-project?rev=325199&view=rev
Log:
Add new interceptor: lstat(2)

Summary:
lstat - get file status

Use it on NetBSD.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka, eugenis

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D42909

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/lstat.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=325199&r1=325198&r2=325199&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Wed Feb 14 18:17:06 2018
@@ -92,6 +92,7 @@
 #define localtime __locatime50
 #define localtime_r __localtime_r50
 #define mktime __mktime50
+#define lstat __lstat50
 #define opendir __opendir30
 #define readdir __readdir30
 #define readdir_r __readdir_r30
@@ -6277,6 +6278,22 @@ INTERCEPTOR(int, stat, const char *path,
 #define INIT_STAT
 #endif
 
+#if SANITIZER_INTERCEPT_LSTAT
+INTERCEPTOR(int, lstat, const char *path, void *buf) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, lstat, path, buf);
+  if (common_flags()->intercept_stat)
+    COMMON_INTERCEPTOR_READ_STRING(ctx, path, 0);
+  int res = REAL(lstat)(path, buf);
+  if (!res)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer::struct_stat_sz);
+  return res;
+}
+#define INIT_LSTAT COMMON_INTERCEPT_FUNCTION(lstat)
+#else
+#define INIT_LSTAT
+#endif
+
 #if SANITIZER_INTERCEPT___XSTAT
 INTERCEPTOR(int, __xstat, int version, const char *path, void *buf) {
   void *ctx;
@@ -6991,6 +7008,7 @@ static void InitializeCommonInterceptors
   INIT_SEND_SENDTO;
   INIT_STAT;
   INIT_EVENTFD_READ_WRITE;
+  INIT_LSTAT;
   INIT___XSTAT;
   INIT___XSTAT64;
   INIT___LXSTAT;

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=325199&r1=325198&r2=325199&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Wed Feb 14 18:17:06 2018
@@ -406,6 +406,7 @@
 
 #define SANITIZER_INTERCEPT_STAT \
   (SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_SOLARIS)
+#define SANITIZER_INTERCEPT_LSTAT SI_NETBSD
 #define SANITIZER_INTERCEPT___XSTAT (!SANITIZER_INTERCEPT_STAT && SI_POSIX)
 #define SANITIZER_INTERCEPT___XSTAT64 SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT___LXSTAT SANITIZER_INTERCEPT___XSTAT

Added: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/lstat.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/lstat.cc?rev=325199&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/lstat.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/lstat.cc Wed Feb 14 18:17:06 2018
@@ -0,0 +1,16 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t
+
+#include <stdlib.h>
+#include <sys/stat.h>
+
+int main(void) {
+  struct stat st;
+
+  if (lstat("/dev/null", &st))
+    exit(1);
+
+  if (!S_ISCHR(st.st_mode))
+    exit(1);
+
+  return 0;
+}




More information about the llvm-commits mailing list