From 48dd3e53466b12a4da540ae6ed35523115120fba Mon Sep 17 00:00:00 2001 From: Brad House Date: Tue, 28 May 2024 15:12:01 -0400 Subject: [PATCH] MacOS UBSAN: another attempt --- src/lib/ares_sysconfig_mac.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lib/ares_sysconfig_mac.c b/src/lib/ares_sysconfig_mac.c index 050e7744..418193f9 100644 --- a/src/lib/ares_sysconfig_mac.c +++ b/src/lib/ares_sysconfig_mac.c @@ -273,13 +273,19 @@ static ares_status_t read_resolvers(dns_resolver_t **resolvers, int nresolvers, int i; for (i = 0; status == ARES_SUCCESS && i < nresolvers; i++) { - dns_resolver_t resolver; + const dns_resolver_t *resolver_ptr; + dns_resolver_t resolver; /* UBSAN doesn't like that this is unaligned, lets use memcpy to get the - * content. */ - memcpy(&resolver, resolvers[i], sizeof(resolver)); - - status = read_resolver(&resolver, sysconfig); + * address. Equivalent to: + * resolver = resolvers[i] + */ + memcpy(&resolver_ptr, resolvers + i, sizeof(resolver_ptr)); + + /* UBSAN. If the pointer is misaligned, try to use memcpy to get the data + * into a new structure that is hopefully aligned properly */ + memcpy(&resolver, resolver_ptr, sizeof(resolver)); + status = read_resolver(&resolver, sysconfig); } return status;