Index: lib/sanitizer_common/sanitizer_common_interceptors.inc =================================================================== --- lib/sanitizer_common/sanitizer_common_interceptors.inc +++ lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -6476,6 +6476,70 @@ #define INIT_ACCT #endif +#if SANITIZER_INTERCEPT_USER_FROM_UID +INTERCEPTOR(const char *, user_from_uid, u32 uid, int nouser) { + void *ctx; + const char *user; + COMMON_INTERCEPTOR_ENTER(ctx, user_from_uid, uid, nouser); + user = REAL(user_from_uid)(uid, nouser); + if (user) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, user, REAL(strlen)(user) + 1); + return user; +} +#define INIT_USER_FROM_UID COMMON_INTERCEPT_FUNCTION(user_from_uid) +#else +#define INIT_USER_FROM_UID +#endif + +#if SANITIZER_INTERCEPT_UID_FROM_USER +INTERCEPTOR(int, uid_from_user, const char *name, u32 *uid) { + void *ctx; + int res; + COMMON_INTERCEPTOR_ENTER(ctx, uid_from_user, name, uid); + if (name) + COMMON_INTERCEPTOR_READ_RANGE(ctx, name, REAL(strlen)(name) + 1); + res = REAL(uid_from_user)(name, uid); + if (uid) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, uid, sizeof(*uid)); + return ret; +} +#define INIT_UID_FROM_USER COMMON_INTERCEPT_FUNCTION(uid_from_user) +#else +#define INIT_UID_FROM_USER +#endif + +#if SANITIZER_INTERCEPT_GROUP_FROM_GID +INTERCEPTOR(const char *, group_from_gid, u32 gid, int nogroup) { + void *ctx; + const char *group; + COMMON_INTERCEPTOR_ENTER(ctx, group_from_gid, gid, nogroup); + group = REAL(group_from_gid)(gid, nogroup); + if (group) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, group, REAL(strlen)(group) + 1); + return group; +} +#define INIT_GROUP_FROM_GID COMMON_INTERCEPT_FUNCTION(group_from_gid) +#else +#define INIT_GROUP_FROM_GID +#endif + +#if SANITIZER_INTERCEPT_GID_FROM_GROUP +INTERCEPTOR(int, gid_from_group, const char *group, u32 *gid) { + void *ctx; + int res; + COMMON_INTERCEPTOR_ENTER(ctx, gid_from_group, group, gid); + if (group) + COMMON_INTERCEPTOR_READ_RANGE(ctx, group, REAL(strlen)(group) + 1); + res = REAL(gid_from_group)(group, gid); + if (gid) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, gid, sizeof(*gid)); + return ret; +} +#define INIT_GID_FROM_GROUP COMMON_INTERCEPT_FUNCTION(gid_from_group) +#else +#define INIT_GID_FROM_GROUP +#endif + static void InitializeCommonInterceptors() { static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1]; interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap(); @@ -6688,6 +6752,10 @@ INIT_WCSLEN; INIT_WCSCAT; INIT_ACCT; + INIT_USER_FROM_UID; + INIT_UID_FROM_USER; + INIT_GROUP_FROM_GID; + INIT_GID_FROM_GROUP; #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 @@ -433,5 +433,9 @@ #define SANITIZER_INTERCEPT_BSD_SIGNAL SI_ANDROID #define SANITIZER_INTERCEPT_ACCT SI_NETBSD +#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 #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H Index: test/sanitizer_common/TestCases/NetBSD/gid_from_group.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/NetBSD/gid_from_group.cc @@ -0,0 +1,16 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t + +#include +#include + +int main(void) { + gid_t nobody; + + if (gid_from_group("nobody", &nobody) == -1) + exit(1); + + if (nobody) + exit(0); + + return 0; +} Index: test/sanitizer_common/TestCases/NetBSD/group_from_gid.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/NetBSD/group_from_gid.cc @@ -0,0 +1,17 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t + +#include +#include +#include + +int main(void) { + const char *nobody; + + if (!(nobody = group_from_gid(0, 0))) + exit(1); + + if (strlen(nobody)) + exit(0); + + return 0; +} Index: test/sanitizer_common/TestCases/NetBSD/uid_from_user.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/NetBSD/uid_from_user.cc @@ -0,0 +1,16 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t + +#include +#include + +int main(void) { + uid_t nobody; + + if (uid_from_user("nobody", &nobody) == -1) + exit(1); + + if (nobody) + exit(0); + + return 0; +} Index: test/sanitizer_common/TestCases/NetBSD/user_from_uid.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/NetBSD/user_from_uid.cc @@ -0,0 +1,17 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t + +#include +#include +#include + +int main(void) { + const char *nobody; + + if (!(nobody = user_from_uid(0, 0))) + exit(1); + + if (strlen(nobody)) + exit(0); + + return 0; +}