FreeBSD sanitizer common, intercept couple of more functions
authorVitaly Buka <vitalybuka@google.com>
Fri, 23 Mar 2018 21:44:59 +0000 (21:44 +0000)
committerVitaly Buka <vitalybuka@google.com>
Fri, 23 Mar 2018 21:44:59 +0000 (21:44 +0000)
Summary:
Intercepts lstat, acct, access, faccessat and strlcpy/strlcat

Patch by David CARLIER

Reviewers: visa, vitalybuka

Subscribers: krytarowski, fedor.sergeev, srhines, kubamracek, llvm-commits, #sanitizers

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

llvm-svn: 328376

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/test/sanitizer_common/TestCases/Posix/access.cc [moved from compiler-rt/test/sanitizer_common/TestCases/NetBSD/access.cc with 100% similarity]
compiler-rt/test/sanitizer_common/TestCases/Posix/devname.cc [moved from compiler-rt/test/sanitizer_common/TestCases/NetBSD/devname.cc with 92% similarity]
compiler-rt/test/sanitizer_common/TestCases/Posix/devname_r.cc [moved from compiler-rt/test/sanitizer_common/TestCases/NetBSD/devname_r.cc with 81% similarity]
compiler-rt/test/sanitizer_common/TestCases/Posix/fgetln.cc [moved from compiler-rt/test/sanitizer_common/TestCases/NetBSD/fgetln.cc with 93% similarity]
compiler-rt/test/sanitizer_common/TestCases/Posix/getpass.cc
compiler-rt/test/sanitizer_common/TestCases/Posix/lstat.cc [moved from compiler-rt/test/sanitizer_common/TestCases/NetBSD/lstat.cc with 100% similarity]
compiler-rt/test/sanitizer_common/TestCases/Posix/strlcat.cc [moved from compiler-rt/test/sanitizer_common/TestCases/NetBSD/strlcat.cc with 97% similarity]
compiler-rt/test/sanitizer_common/TestCases/Posix/strlcpy.cc [moved from compiler-rt/test/sanitizer_common/TestCases/NetBSD/strlcpy.cc with 97% similarity]
compiler-rt/test/sanitizer_common/lit.common.cfg

index c751f3c..56102c9 100644 (file)
 
 #define SANITIZER_INTERCEPT_STAT \
   (SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_OPENBSD || SI_SOLARIS)
-#define SANITIZER_INTERCEPT_LSTAT SI_NETBSD
+#define SANITIZER_INTERCEPT_LSTAT (SI_NETBSD || SI_FREEBSD)
 #define SANITIZER_INTERCEPT___XSTAT (!SANITIZER_INTERCEPT_STAT && SI_POSIX)
 #define SANITIZER_INTERCEPT___XSTAT64 SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT___LXSTAT SANITIZER_INTERCEPT___XSTAT
 #define SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION (!SI_WINDOWS && SI_NOT_FUCHSIA)
 #define SANITIZER_INTERCEPT_BSD_SIGNAL SI_ANDROID
 
-#define SANITIZER_INTERCEPT_ACCT (SI_NETBSD || SI_OPENBSD)
+#define SANITIZER_INTERCEPT_ACCT (SI_NETBSD || SI_OPENBSD || SI_FREEBSD)
 #define SANITIZER_INTERCEPT_USER_FROM_UID SI_NETBSD
 #define SANITIZER_INTERCEPT_UID_FROM_USER SI_NETBSD
 #define SANITIZER_INTERCEPT_GROUP_FROM_GID SI_NETBSD
 #define SANITIZER_INTERCEPT_GID_FROM_GROUP SI_NETBSD
-#define SANITIZER_INTERCEPT_ACCESS (SI_NETBSD || SI_OPENBSD)
-#define SANITIZER_INTERCEPT_FACCESSAT (SI_NETBSD || SI_OPENBSD)
+#define SANITIZER_INTERCEPT_ACCESS (SI_NETBSD || SI_OPENBSD || SI_FREEBSD)
+#define SANITIZER_INTERCEPT_FACCESSAT (SI_NETBSD || SI_OPENBSD || SI_FREEBSD)
 #define SANITIZER_INTERCEPT_GETGROUPLIST (SI_NETBSD || SI_OPENBSD)
-#define SANITIZER_INTERCEPT_GETGROUPMEMBERSHIP SI_NETBSD
-#define SANITIZER_INTERCEPT_STRLCPY (SI_NETBSD || SI_OPENBSD)
+#define SANITIZER_INTERCEPT_STRLCPY                                            \
+  (SI_NETBSD || SI_FREEBSD || SI_OPENBSD || SI_MAC || SI_ANDROID)
 
 #define SANITIZER_INTERCEPT_NAME_TO_HANDLE_AT SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT_OPEN_BY_HANDLE_AT SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT_READLINKAT \
   (SI_POSIX && !SI_MAC_DEPLOYMENT_BELOW_10_10)
 
-#define SANITIZER_INTERCEPT_DEVNAME (SI_NETBSD || SI_OPENBSD)
-#define SANITIZER_INTERCEPT_DEVNAME_R SI_NETBSD
-#define SANITIZER_INTERCEPT_FGETLN SI_NETBSD
-#define SANITIZER_INTERCEPT_STRMODE SI_NETBSD
+#define SANITIZER_INTERCEPT_DEVNAME (SI_NETBSD || SI_OPENBSD || SI_FREEBSD)
+#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_PROTOENT SI_NETBSD
 #define SANITIZER_INTERCEPT_NETENT SI_NETBSD
@@ -1,4 +1,5 @@
 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: linux, solaris
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -1,4 +1,5 @@
 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: linux, solaris
 
 #include <sys/cdefs.h>
 #include <sys/stat.h>
@@ -16,7 +17,7 @@ int main(void) {
 
   type = S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK;
 
-  if (devname_r(st.st_rdev, type, name, __arraycount(name)))
+  if (devname_r(st.st_rdev, type, name, sizeof(name)))
     exit(1);
 
   printf("%s\n", name);
index b91a3d7..bf198ef 100644 (file)
@@ -5,13 +5,19 @@
 
 #include <assert.h>
 #include <stdio.h>
-#include <unistd.h>
 #include <string.h>
 #if __linux__
 #include <pty.h>
+#elif defined(__FreeBSD__)
+#include <libutil.h>
+#include <pwd.h>
+#include <sys/ioctl.h>
+#include <sys/termios.h>
+#include <sys/types.h>
 #else
 #include <util.h>
 #endif
+#include <unistd.h>
 
 int
 main (int argc, char** argv)
index 72e3e5e..0e9183b 100644 (file)
@@ -59,5 +59,5 @@ config.substitutions.append( ('%env_tool_opts=',
 
 config.suffixes = ['.c', '.cc', '.cpp']
 
-if config.host_os not in ['Linux', 'Darwin', 'NetBSD']:
+if config.host_os not in ['Linux', 'Darwin', 'NetBSD', 'FreeBSD']:
   config.unsupported = True