[PATCH] D42064: Add new NetBSD interceptors: getgrouplist(3) & getgroupmembership(3)

Kamil Rytarowski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 15 04:46:40 PST 2018


krytarowski created this revision.
krytarowski added reviewers: vitalybuka, joerg.
krytarowski added a project: Sanitizers.
Herald added a subscriber: kubamracek.

  GETGROUPLIST(3)            Library Functions Manual            GETGROUPLIST(3)
  
  NAME
       getgrouplist, getgroupmembership, -- calculate group access list
  
  LIBRARY
       Standard C Library (libc, -lc)
  
  SYNOPSIS
       #include <unistd.h>
  
       int
       getgrouplist(const char *name, gid_t basegid, gid_t *groups,
           int *ngroups);
  
       int
       getgroupmembership(const char *name, gid_t basegid, gid_t *groups,
           int maxgrp, int *ngroups);
  ``
  
  Sponsored by <The NetBSD Foundation>


Repository:
  rL LLVM

https://reviews.llvm.org/D42064

Files:
  lib/sanitizer_common/sanitizer_common_interceptors.inc
  lib/sanitizer_common/sanitizer_platform_interceptors.h


Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -432,4 +432,6 @@
 #define SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION (!SI_WINDOWS && SI_NOT_FUCHSIA)
 #define SANITIZER_INTERCEPT_BSD_SIGNAL SI_ANDROID
 
+#define SANITIZER_INTERCEPT_GETGROUPLIST 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
@@ -6463,6 +6463,39 @@
 #define INIT_WCSCAT
 #endif
 
+#if SANITIZER_INTERCEPT_GETGROUPLIST
+INTERCEPTOR(int, getgrouplist, char *name, u32 basegid, u32 *groups, int *ngroups) {
+  void *ctx;
+  int res;
+  COMMON_INTERCEPTOR_ENTER(ctx, getgrouplist, name, basegid, groups, ngroups);
+  if (name) {
+    COMMON_INTERCEPTOR_READ_RANGE(ctx, name, REAL(strlen)(name) + 1);
+  }
+  res = REAL(getgrouplist)(name, basegid, groups, ngroups);
+  if (groups && ngroups)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, groups, sizeof(*groups) * (*ngroups));
+  return res;
+}
+INTERCEPTOR(int, getgroupmembership, char *name, u32 basegid, u32 *groups, int maxgrp, int *ngroups) {
+  void *ctx;
+  int res;
+  COMMON_INTERCEPTOR_ENTER(ctx, getgroupmembership, name, basegid, groups, maxgrp, ngroups);
+  if (name) {
+    COMMON_INTERCEPTOR_READ_RANGE(ctx, name, REAL(strlen)(name) + 1);
+  }
+  res = REAL(getgroupmembership)(name, basegid, groups, maxgrp, ngroups);
+  if (groups && ngroups)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, groups, sizeof(*groups) * (*ngroups));
+  return res;
+}
+
+#define INIT_GETGROUPLIST \
+  COMMON_INTERCEPT_FUNCTION(getgrouplist); \
+  COMMON_INTERCEPT_FUNCTION(getgroupmembership)
+#else
+#define INIT_GETGROUPLIST
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -6674,6 +6707,7 @@
   INIT_GETLOADAVG;
   INIT_WCSLEN;
   INIT_WCSCAT;
+  INIT_GETGROUPLIST;
 
 #if SANITIZER_NETBSD
   COMMON_INTERCEPT_FUNCTION(__libc_mutex_lock);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42064.129839.patch
Type: text/x-patch
Size: 2365 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180115/ef22da75/attachment.bin>


More information about the llvm-commits mailing list