MacOS UBSAN: another attempt

pull/772/head
Brad House 8 months ago
parent c40bdac234
commit 48dd3e5346
  1. 16
      src/lib/ares_sysconfig_mac.c

@ -273,13 +273,19 @@ static ares_status_t read_resolvers(dns_resolver_t **resolvers, int nresolvers,
int i; int i;
for (i = 0; status == ARES_SUCCESS && i < nresolvers; 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 /* UBSAN doesn't like that this is unaligned, lets use memcpy to get the
* content. */ * address. Equivalent to:
memcpy(&resolver, resolvers[i], sizeof(resolver)); * resolver = resolvers[i]
*/
status = read_resolver(&resolver, sysconfig); 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; return status;

Loading…
Cancel
Save