summaryrefslogtreecommitdiffstats
path: root/pwcache.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-08-13 10:26:31 -0400
committerTavian Barnes <tavianator@tavianator.com>2020-08-13 10:26:54 -0400
commit05a04ee57e52980e9d651ee6e1764ba6f0e4ea1c (patch)
tree48efeeaaedd7a86fce082092b2a8ccfdf0e61628 /pwcache.c
parent564142a029fda86b2d87f8f39c12acea34241098 (diff)
downloadbfs-05a04ee57e52980e9d651ee6e1764ba6f0e4ea1c.tar.xz
pwcache: Work around gr_mem being misaligned on macOS
C.f. https://github.com/php/php-src/commit/d80f0ff6c0a557d8c993a9d2bd006fb488f6d564
Diffstat (limited to 'pwcache.c')
-rw-r--r--pwcache.c17
1 files 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;