From 05a04ee57e52980e9d651ee6e1764ba6f0e4ea1c Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 13 Aug 2020 10:26:31 -0400 Subject: pwcache: Work around gr_mem being misaligned on macOS C.f. https://github.com/php/php-src/commit/d80f0ff6c0a557d8c993a9d2bd006fb488f6d564 --- pwcache.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pwcache.c b/pwcache.c index 4fca134..d488625 100644 --- a/pwcache.c +++ b/pwcache.c @@ -152,6 +152,17 @@ struct bfs_groups { struct trie by_gid; }; +/** + * struct group::gr_mem isn't properly aligned on macOS, so do this to avoid + * ASAN warnings. + */ +static char *next_gr_mem(void **gr_mem) { + char *mem; + memcpy(&mem, *gr_mem, sizeof(mem)); + *gr_mem = (char *)*gr_mem + sizeof(mem); + return mem; +} + struct bfs_groups *bfs_parse_groups(void) { int error; @@ -190,10 +201,10 @@ struct bfs_groups *bfs_parse_groups(void) { goto fail_end; } - char **members = ent->gr_mem; + void *members = ent->gr_mem; ent->gr_mem = NULL; - for (char **mem = members; *mem; ++mem) { - char *dup = strdup(*mem); + for (char *mem = next_gr_mem(&members); mem; mem = next_gr_mem(&members)) { + char *dup = strdup(mem); if (!dup) { error = errno; goto fail_end; -- cgit v1.2.3