diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2020-08-13 10:26:31 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2020-08-13 10:26:54 -0400 |
commit | 05a04ee57e52980e9d651ee6e1764ba6f0e4ea1c (patch) | |
tree | 48efeeaaedd7a86fce082092b2a8ccfdf0e61628 | |
parent | 564142a029fda86b2d87f8f39c12acea34241098 (diff) | |
download | bfs-05a04ee57e52980e9d651ee6e1764ba6f0e4ea1c.tar.xz |
pwcache: Work around gr_mem being misaligned on macOS
C.f. https://github.com/php/php-src/commit/d80f0ff6c0a557d8c993a9d2bd006fb488f6d564
-rw-r--r-- | pwcache.c | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -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; |