ares_getaddrinfo() was returning the wrong size for ai_addrlen

ai_addrlen was erroneously returning 16 bytes instead of the
sizeof(struct sockaddr_in6).  This is a regression introduced
in 1.18.0.

Reported by: James Brown <jbrown@easypost.com>
Fix By: Brad House (@bradh352)
pull/436/head
bradh352 3 years ago
parent 640a0ea072
commit 71adb3c417
  1. 8
      src/lib/ares__addrinfo_localhost.c
  2. 4
      test/ares-test-mock-ai.cc

@ -60,13 +60,13 @@ int ares_append_ai_node(int aftype,
}
memset(sin, 0, sizeof(*sin));
memcpy(&sin->sin_addr.s_addr, adata, sizeof(struct in_addr));
memcpy(&sin->sin_addr.s_addr, adata, sizeof(sin->sin_addr.s_addr));
sin->sin_family = AF_INET;
sin->sin_port = htons(port);
node->ai_addr = (struct sockaddr *)sin;
node->ai_family = AF_INET;
node->ai_addrlen = sizeof(struct sockaddr_in);
node->ai_addrlen = sizeof(*sin);
node->ai_addr = (struct sockaddr *)sin;
node->ai_ttl = ttl;
}
@ -80,13 +80,13 @@ int ares_append_ai_node(int aftype,
}
memset(sin6, 0, sizeof(*sin6));
memcpy(&sin6->sin6_addr.s6_addr, adata, sizeof(struct ares_in6_addr));
memcpy(&sin6->sin6_addr.s6_addr, adata, sizeof(sin6->sin6_addr.s6_addr));
sin6->sin6_family = AF_INET6;
sin6->sin6_port = htons(port);
node->ai_addr = (struct sockaddr *)sin6;
node->ai_family = AF_INET6;
node->ai_addrlen = sizeof(struct ares_in6_addr);
node->ai_addrlen = sizeof(*sin6);
node->ai_addr = (struct sockaddr *)sin6;
node->ai_ttl = ttl;
}

@ -32,6 +32,8 @@ MATCHER_P(IncludesV4Address, address, "") {
for (const ares_addrinfo_node* ai = arg->nodes; ai != NULL; ai = ai->ai_next) {
if (ai->ai_family != AF_INET)
continue;
if (ai->ai_addrlen != sizeof(struct sockaddr_in))
continue;
if (reinterpret_cast<sockaddr_in*>(ai->ai_addr)->sin_addr.s_addr ==
addressnum.s_addr)
return true; // found
@ -49,6 +51,8 @@ MATCHER_P(IncludesV6Address, address, "") {
for (const ares_addrinfo_node* ai = arg->nodes; ai != NULL; ai = ai->ai_next) {
if (ai->ai_family != AF_INET6)
continue;
if (ai->ai_addrlen != sizeof(struct sockaddr_in6))
continue;
if (!memcmp(
reinterpret_cast<sockaddr_in6*>(ai->ai_addr)->sin6_addr.s6_addr,
addressnum.s6_addr, sizeof(addressnum.s6_addr)))

Loading…
Cancel
Save