Skip to content

Commit

Permalink
deps: update to c-ares 1.17.1
Browse files Browse the repository at this point in the history
PR-URL: #36207
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
lxdicted authored and targos committed May 1, 2021
1 parent 5ef609a commit 5747dff
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 56 deletions.
4 changes: 2 additions & 2 deletions deps/cares/include/ares_version.h
Expand Up @@ -6,12 +6,12 @@
#define ARES_COPYRIGHT "2004 - 2020 Daniel Stenberg, <daniel@haxx.se>."

#define ARES_VERSION_MAJOR 1
#define ARES_VERSION_MINOR 16
#define ARES_VERSION_MINOR 17
#define ARES_VERSION_PATCH 1
#define ARES_VERSION ((ARES_VERSION_MAJOR<<16)|\
(ARES_VERSION_MINOR<<8)|\
(ARES_VERSION_PATCH))
#define ARES_VERSION_STR "1.16.1"
#define ARES_VERSION_STR "1.17.1"

#if (ARES_VERSION >= 0x010700)
# define CARES_HAVE_ARES_LIBRARY_INIT 1
Expand Down
7 changes: 6 additions & 1 deletion deps/cares/include/nameser.h
Expand Up @@ -88,7 +88,7 @@ typedef enum __ns_type {
ns_t_maila = 254, /* Transfer mail agent records. */
ns_t_any = 255, /* Wildcard match. */
ns_t_zxfr = 256, /* BIND-specific, nonstandard. */
ns_t_caa = 257, /* CA Authorization (RFC8659) */
ns_t_caa = 257, /* Certification Authority Authorization. */
ns_t_max = 65536
} ns_type;

Expand Down Expand Up @@ -210,4 +210,9 @@ typedef enum __ns_rcode {

#endif /* HAVE_ARPA_NAMESER_COMPAT_H */

/* Android's bionic arpa/nameser_compat.h, nor glibc versions prior to 2.25 have T_OPT defined */
#ifndef T_OPT
# define T_OPT ns_t_opt
#endif

#endif /* ARES_NAMESER_H */
8 changes: 6 additions & 2 deletions deps/cares/src/ares__readaddrinfo.c
Expand Up @@ -163,6 +163,10 @@ int ares__readaddrinfo(FILE *fp,
continue;
}

/* Zero-out 'addr' struct, as there are members that we may not set, especially
* for ipv6. We don't want garbage data */
memset(&addr, 0, sizeof(addr));

/*
* Convert address string to network address for the requested families.
* Actual address family possible values are AF_INET and AF_INET6 only.
Expand All @@ -179,7 +183,7 @@ int ares__readaddrinfo(FILE *fp,
}

node->ai_family = addr.sa.sa_family = AF_INET;
node->ai_addrlen = sizeof(sizeof(addr.sa4));
node->ai_addrlen = sizeof(addr.sa4);
node->ai_addr = ares_malloc(sizeof(addr.sa4));
if (!node->ai_addr)
{
Expand All @@ -200,7 +204,7 @@ int ares__readaddrinfo(FILE *fp,
}

node->ai_family = addr.sa.sa_family = AF_INET6;
node->ai_addrlen = sizeof(sizeof(addr.sa6));
node->ai_addrlen = sizeof(addr.sa6);
node->ai_addr = ares_malloc(sizeof(addr.sa6));
if (!node->ai_addr)
{
Expand Down
21 changes: 11 additions & 10 deletions deps/cares/src/ares__sortaddrinfo.c
Expand Up @@ -85,11 +85,12 @@ struct addrinfo_sort_elem
#define ARES_IN6_IS_ADDR_6BONE(a) \
(((a)->s6_addr[0] == 0x3f) && ((a)->s6_addr[1] == 0xfe))


static int get_scope(const struct sockaddr *addr)
{
if (addr->sa_family == AF_INET6)
{
const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
const struct sockaddr_in6 *addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
if (IN6_IS_ADDR_MULTICAST(&addr6->sin6_addr))
{
return ARES_IPV6_ADDR_MC_SCOPE(&addr6->sin6_addr);
Expand All @@ -114,7 +115,7 @@ static int get_scope(const struct sockaddr *addr)
}
else if (addr->sa_family == AF_INET)
{
const struct sockaddr_in *addr4 = (const struct sockaddr_in *)addr;
const struct sockaddr_in *addr4 = CARES_INADDR_CAST(const struct sockaddr_in *, addr);
unsigned long int na = ntohl(addr4->sin_addr.s_addr);
if (ARES_IN_LOOPBACK(na) || /* 127.0.0.0/8 */
(na & 0xffff0000) == 0xa9fe0000) /* 169.254.0.0/16 */
Expand Down Expand Up @@ -149,7 +150,7 @@ static int get_label(const struct sockaddr *addr)
}
else if (addr->sa_family == AF_INET6)
{
const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
const struct sockaddr_in6 *addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr))
{
return 0;
Expand Down Expand Up @@ -210,7 +211,7 @@ static int get_precedence(const struct sockaddr *addr)
}
else if (addr->sa_family == AF_INET6)
{
const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
const struct sockaddr_in6 *addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr))
{
return 50;
Expand Down Expand Up @@ -353,10 +354,10 @@ static int rfc6724_compare(const void *ptr1, const void *ptr2)
{
const struct sockaddr_in6 *a1_src = &a1->src_addr.sa6;
const struct sockaddr_in6 *a1_dst =
(const struct sockaddr_in6 *)a1->ai->ai_addr;
CARES_INADDR_CAST(const struct sockaddr_in6 *, a1->ai->ai_addr);
const struct sockaddr_in6 *a2_src = &a2->src_addr.sa6;
const struct sockaddr_in6 *a2_dst =
(const struct sockaddr_in6 *)a2->ai->ai_addr;
CARES_INADDR_CAST(const struct sockaddr_in6 *, a2->ai->ai_addr);
prefixlen1 = common_prefix_len(&a1_src->sin6_addr, &a1_dst->sin6_addr);
prefixlen2 = common_prefix_len(&a2_src->sin6_addr, &a2_dst->sin6_addr);
if (prefixlen1 != prefixlen2)
Expand Down Expand Up @@ -384,7 +385,7 @@ static int find_src_addr(ares_channel channel,
const struct sockaddr *addr,
struct sockaddr *src_addr)
{
int sock;
ares_socket_t sock;
int ret;
ares_socklen_t len;

Expand All @@ -402,7 +403,7 @@ static int find_src_addr(ares_channel channel,
}

sock = ares__open_socket(channel, addr->sa_family, SOCK_DGRAM, IPPROTO_UDP);
if (sock == -1)
if (sock == ARES_SOCKET_BAD)
{
if (errno == EAFNOSUPPORT)
{
Expand All @@ -426,7 +427,7 @@ static int find_src_addr(ares_channel channel,
return 0;
}

if (getsockname(sock, src_addr, &len) == -1)
if (getsockname(sock, src_addr, &len) != 0)
{
ares__close_socket(channel, sock);
return -1;
Expand Down Expand Up @@ -491,4 +492,4 @@ int ares__sortaddrinfo(ares_channel channel, struct ares_addrinfo_node *list_sen

ares_free(elems);
return ARES_SUCCESS;
}
}
11 changes: 11 additions & 0 deletions deps/cares/src/ares_getaddrinfo.c
Expand Up @@ -386,6 +386,9 @@ static int fake_addrinfo(const char *name,
}
}

node->ai_socktype = hints->ai_socktype;
node->ai_protocol = hints->ai_protocol;

callback(arg, ARES_SUCCESS, 0, ai);
return 1;
}
Expand All @@ -406,6 +409,8 @@ static void end_hquery(struct host_query *hquery, int status)
/* Set port into each address (resolved separately). */
while (next)
{
next->ai_socktype = hquery->hints.ai_socktype;
next->ai_protocol = hquery->hints.ai_protocol;
if (next->ai_family == AF_INET)
{
(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr))->sin_port = htons(hquery->port);
Expand Down Expand Up @@ -754,12 +759,18 @@ static int as_is_first(const struct host_query* hquery)
{
char* p;
int ndots = 0;
size_t nname = strlen(hquery->name);
for (p = hquery->name; *p; p++)
{
if (*p == '.')
{
ndots++;
}
}
if (nname && hquery->name[nname-1] == '.')
{
/* prevent ARES_EBADNAME for valid FQDN, where ndots < channel->ndots */
return 1;
}
return ndots >= hquery->channel->ndots;
}
1 change: 0 additions & 1 deletion deps/cares/src/ares_gethostbyaddr.c
Expand Up @@ -208,7 +208,6 @@ static int file_lookup(struct ares_addr *addr, struct hostent **host)
strcat(PATH_HOSTS, WIN_PATH_HOSTS);

#elif defined(WATT32)
extern const char *_w32_GetHostsFile (void);
const char *PATH_HOSTS = _w32_GetHostsFile();

if (!PATH_HOSTS)
Expand Down
15 changes: 9 additions & 6 deletions deps/cares/src/ares_gethostbyname.c
Expand Up @@ -258,7 +258,7 @@ static int fake_hostent(const char *name, int family,
struct in_addr in;
struct ares_in6_addr in6;

if (family == AF_INET || family == AF_INET6)
if (family == AF_INET || family == AF_UNSPEC)
{
/* It only looks like an IP address if it's all numbers and dots. */
int numdots = 0, valid = 1;
Expand All @@ -276,13 +276,17 @@ static int fake_hostent(const char *name, int family,
/* if we don't have 3 dots, it is illegal
* (although inet_pton doesn't think so).
*/
if (numdots != 3 || !valid)
if (numdots != 3 || !valid) {
result = 0;
else
} else {
result = (ares_inet_pton(AF_INET, name, &in) < 1 ? 0 : 1);
}

if (result)
family = AF_INET;
/*
* Set address family in case of failure,
* as we will try to convert it later afterwards
*/
family = result ? AF_INET : AF_INET6;
}
if (family == AF_INET6)
result = (ares_inet_pton(AF_INET6, name, &in6) < 1 ? 0 : 1);
Expand Down Expand Up @@ -383,7 +387,6 @@ static int file_lookup(const char *name, int family, struct hostent **host)
strcat(PATH_HOSTS, WIN_PATH_HOSTS);

#elif defined(WATT32)
extern const char *_w32_GetHostsFile (void);
const char *PATH_HOSTS = _w32_GetHostsFile();

if (!PATH_HOSTS)
Expand Down
20 changes: 4 additions & 16 deletions deps/cares/src/ares_init.c
Expand Up @@ -115,20 +115,6 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
int status = ARES_SUCCESS;
struct timeval now;

#ifdef CURLDEBUG
const char *env = getenv("CARES_MEMDEBUG");

if (env)
curl_memdebug(env);
env = getenv("CARES_MEMLIMIT");
if (env) {
char *endptr;
long num = strtol(env, &endptr, 10);
if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
curl_memlimit(num);
}
#endif

if (ares_library_initialized() != ARES_SUCCESS)
return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */

Expand Down Expand Up @@ -1611,7 +1597,8 @@ static int init_by_resolv_conf(ares_channel channel)
if (channel->nservers == -1) {
union res_sockaddr_union addr[MAXNS];
int nscount = res_getservers(&res, addr, MAXNS);
for (int i = 0; i < nscount; ++i) {
int i;
for (i = 0; i < nscount; ++i) {
char str[INET6_ADDRSTRLEN];
int config_status;
sa_family_t family = addr[i].sin.sin_family;
Expand Down Expand Up @@ -1639,8 +1626,9 @@ static int init_by_resolv_conf(ares_channel channel)
if (!channel->domains) {
status = ARES_ENOMEM;
} else {
int i;
channel->ndomains = entries;
for (int i = 0; i < channel->ndomains; ++i) {
for (i = 0; i < channel->ndomains; ++i) {
channel->domains[i] = ares_strdup(res.dnsrch[i]);
if (!channel->domains[i])
status = ARES_ENOMEM;
Expand Down
2 changes: 1 addition & 1 deletion deps/cares/src/ares_parse_caa_reply.c
Expand Up @@ -140,7 +140,7 @@ ares_parse_caa_reply (const unsigned char *abuf, int alen,
status = ARES_EBADRESP;
break;
}
caa_curr->critical = (int)*strptr++;
caa_curr->critical = (int)*strptr++;
caa_curr->plength = (int)*strptr++;
if (caa_curr->plength <= 0 || (int)caa_curr->plength >= rr_len - 2)
{
Expand Down
9 changes: 6 additions & 3 deletions deps/cares/src/ares_parse_soa_reply.c
Expand Up @@ -62,13 +62,16 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
return ARES_EBADRESP;
if (ancount == 0)
return ARES_EBADRESP;

aptr = abuf + HFIXEDSZ;

/* query name */
status = ares__expand_name_for_response(aptr, abuf, alen, &qname, &len);
if (status != ARES_SUCCESS)
goto failed_stat;

if (alen <= len + HFIXEDSZ + 1)
goto failed;
aptr += len;

qclass = DNS_QUESTION_TYPE(aptr);
Expand Down Expand Up @@ -161,9 +164,9 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
return ARES_SUCCESS;
}
aptr += rr_len;

ares_free(rr_name);

if (aptr > abuf + alen)
goto failed_stat;
}
Expand Down
10 changes: 1 addition & 9 deletions deps/cares/src/ares_private.h
Expand Up @@ -74,6 +74,7 @@
#elif defined(WATT32)

#define PATH_RESOLV_CONF "/dev/ENV/etc/resolv.conf"
W32_FUNC const char *_w32_GetHostsFile (void);

#elif defined(NETWARE)

Expand Down Expand Up @@ -415,13 +416,4 @@ int ares__connect_socket(ares_channel channel,
(c)->sock_state_cb((c)->sock_state_cb_data, (s), (r), (w)); \
} WHILE_FALSE

#ifdef CURLDEBUG
/* This is low-level hard-hacking memory leak tracking and similar. Using the
libcurl lowlevel code from within library is ugly and only works when
c-ares is built and linked with a similarly curldebug-enabled libcurl,
but we do this anyway for convenience. */
#define HEADER_CURL_SETUP_ONCE_H
#include "../lib/memdebug.h"
#endif

#endif /* __ARES_PRIVATE_H */

0 comments on commit 5747dff

Please sign in to comment.