Index: lib/sanitizer_common/sanitizer_common_interceptors.inc =================================================================== --- lib/sanitizer_common/sanitizer_common_interceptors.inc +++ lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -6566,6 +6566,46 @@ #define INIT_FACCESSAT #endif +#if SANITIZER_INTERCEPT_GETGROUPLIST +INTERCEPTOR(int, getgrouplist, const 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); + if (ngroups) + COMMON_INTERCEPTOR_READ_RANGE(ctx, ngroups, sizeof(*ngroups)); + res = REAL(getgrouplist)(name, basegid, groups, ngroups); + if (!res && groups && ngroups) { + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, groups, sizeof(*groups) * (*ngroups)); + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ngroups, sizeof(*ngroups)); + } + return res; +} + +INTERCEPTOR(int, getgroupmembership, const 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 (!res && groups && ngroups) { + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, groups, sizeof(*groups) * (*ngroups)); + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ngroups, sizeof(*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(); @@ -6784,6 +6824,7 @@ INIT_GID_FROM_GROUP; INIT_ACCESS; INIT_FACCESSAT; + INIT_GETGROUPLIST; #if SANITIZER_NETBSD COMMON_INTERCEPT_FUNCTION(__libc_mutex_lock); Index: lib/sanitizer_common/sanitizer_platform_interceptors.h =================================================================== --- lib/sanitizer_common/sanitizer_platform_interceptors.h +++ lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -439,5 +439,6 @@ #define SANITIZER_INTERCEPT_GID_FROM_GROUP SI_NETBSD #define SANITIZER_INTERCEPT_ACCESS SI_NETBSD #define SANITIZER_INTERCEPT_FACCESSAT SI_NETBSD +#define SANITIZER_INTERCEPT_GETGROUPLIST SI_NETBSD #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H Index: test/sanitizer_common/TestCases/NetBSD/getgrouplist.cc =================================================================== --- test/sanitizer_common/TestCases/NetBSD/getgrouplist.cc +++ test/sanitizer_common/TestCases/NetBSD/getgrouplist.cc @@ -0,0 +1,29 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t + +#include +#include +#include + +int main(void) { + gid_t *groups; + gid_t nobody; + int ngroups; + + ngroups = sysconf(_SC_NGROUPS_MAX); + groups = (gid_t *)malloc(ngroups * sizeof(gid_t)); + if (!groups) + exit(1); + + if (gid_from_group("nobody", &nobody) == -1) + exit(1); + + if (getgrouplist("nobody", nobody, groups, &ngroups)) + exit(1); + + if (groups && ngroups) { + free(groups); + exit(0); + } + + return -1; +} Index: test/sanitizer_common/TestCases/NetBSD/getgroupmembership.cc =================================================================== --- test/sanitizer_common/TestCases/NetBSD/getgroupmembership.cc +++ test/sanitizer_common/TestCases/NetBSD/getgroupmembership.cc @@ -0,0 +1,30 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t + +#include +#include +#include + +int main(void) { + gid_t *groups; + gid_t nobody; + int ngroups; + int maxgrp; + + maxgrp = sysconf(_SC_NGROUPS_MAX); + groups = (gid_t *)malloc(maxgrp * sizeof(gid_t)); + if (!groups) + exit(1); + + if (gid_from_group("nobody", &nobody) == -1) + exit(1); + + if (getgroupmembership("nobody", nobody, groups, maxgrp, &ngroups)) + exit(1); + + if (groups && ngroups) { + free(groups); + exit(0); + } + + return -1; +}