Skip to content

Commit cb4652e

Browse files
lxdictedtargos
authored andcommitted
deps: update to c-ares 1.17.1
PR-URL: #36207 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Shelley Vohr <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 81e603b commit cb4652e

14 files changed

+143
-56
lines changed

deps/cares/include/ares_version.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
#define ARES_COPYRIGHT "2004 - 2020 Daniel Stenberg, <[email protected]>."
77

88
#define ARES_VERSION_MAJOR 1
9-
#define ARES_VERSION_MINOR 16
9+
#define ARES_VERSION_MINOR 17
1010
#define ARES_VERSION_PATCH 1
1111
#define ARES_VERSION ((ARES_VERSION_MAJOR<<16)|\
1212
(ARES_VERSION_MINOR<<8)|\
1313
(ARES_VERSION_PATCH))
14-
#define ARES_VERSION_STR "1.16.1"
14+
#define ARES_VERSION_STR "1.17.1"
1515

1616
#if (ARES_VERSION >= 0x010700)
1717
# define CARES_HAVE_ARES_LIBRARY_INIT 1

deps/cares/include/nameser.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ typedef enum __ns_type {
8888
ns_t_maila = 254, /* Transfer mail agent records. */
8989
ns_t_any = 255, /* Wildcard match. */
9090
ns_t_zxfr = 256, /* BIND-specific, nonstandard. */
91-
ns_t_caa = 257, /* CA Authorization (RFC8659) */
91+
ns_t_caa = 257, /* Certification Authority Authorization. */
9292
ns_t_max = 65536
9393
} ns_type;
9494

@@ -210,4 +210,9 @@ typedef enum __ns_rcode {
210210

211211
#endif /* HAVE_ARPA_NAMESER_COMPAT_H */
212212

213+
/* Android's bionic arpa/nameser_compat.h, nor glibc versions prior to 2.25 have T_OPT defined */
214+
#ifndef T_OPT
215+
# define T_OPT ns_t_opt
216+
#endif
217+
213218
#endif /* ARES_NAMESER_H */

deps/cares/src/ares__readaddrinfo.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ int ares__readaddrinfo(FILE *fp,
163163
continue;
164164
}
165165

166+
/* Zero-out 'addr' struct, as there are members that we may not set, especially
167+
* for ipv6. We don't want garbage data */
168+
memset(&addr, 0, sizeof(addr));
169+
166170
/*
167171
* Convert address string to network address for the requested families.
168172
* Actual address family possible values are AF_INET and AF_INET6 only.
@@ -179,7 +183,7 @@ int ares__readaddrinfo(FILE *fp,
179183
}
180184

181185
node->ai_family = addr.sa.sa_family = AF_INET;
182-
node->ai_addrlen = sizeof(sizeof(addr.sa4));
186+
node->ai_addrlen = sizeof(addr.sa4);
183187
node->ai_addr = ares_malloc(sizeof(addr.sa4));
184188
if (!node->ai_addr)
185189
{
@@ -200,7 +204,7 @@ int ares__readaddrinfo(FILE *fp,
200204
}
201205

202206
node->ai_family = addr.sa.sa_family = AF_INET6;
203-
node->ai_addrlen = sizeof(sizeof(addr.sa6));
207+
node->ai_addrlen = sizeof(addr.sa6);
204208
node->ai_addr = ares_malloc(sizeof(addr.sa6));
205209
if (!node->ai_addr)
206210
{

deps/cares/src/ares__sortaddrinfo.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ struct addrinfo_sort_elem
8585
#define ARES_IN6_IS_ADDR_6BONE(a) \
8686
(((a)->s6_addr[0] == 0x3f) && ((a)->s6_addr[1] == 0xfe))
8787

88+
8889
static int get_scope(const struct sockaddr *addr)
8990
{
9091
if (addr->sa_family == AF_INET6)
9192
{
92-
const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
93+
const struct sockaddr_in6 *addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
9394
if (IN6_IS_ADDR_MULTICAST(&addr6->sin6_addr))
9495
{
9596
return ARES_IPV6_ADDR_MC_SCOPE(&addr6->sin6_addr);
@@ -114,7 +115,7 @@ static int get_scope(const struct sockaddr *addr)
114115
}
115116
else if (addr->sa_family == AF_INET)
116117
{
117-
const struct sockaddr_in *addr4 = (const struct sockaddr_in *)addr;
118+
const struct sockaddr_in *addr4 = CARES_INADDR_CAST(const struct sockaddr_in *, addr);
118119
unsigned long int na = ntohl(addr4->sin_addr.s_addr);
119120
if (ARES_IN_LOOPBACK(na) || /* 127.0.0.0/8 */
120121
(na & 0xffff0000) == 0xa9fe0000) /* 169.254.0.0/16 */
@@ -149,7 +150,7 @@ static int get_label(const struct sockaddr *addr)
149150
}
150151
else if (addr->sa_family == AF_INET6)
151152
{
152-
const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
153+
const struct sockaddr_in6 *addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
153154
if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr))
154155
{
155156
return 0;
@@ -210,7 +211,7 @@ static int get_precedence(const struct sockaddr *addr)
210211
}
211212
else if (addr->sa_family == AF_INET6)
212213
{
213-
const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
214+
const struct sockaddr_in6 *addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
214215
if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr))
215216
{
216217
return 50;
@@ -353,10 +354,10 @@ static int rfc6724_compare(const void *ptr1, const void *ptr2)
353354
{
354355
const struct sockaddr_in6 *a1_src = &a1->src_addr.sa6;
355356
const struct sockaddr_in6 *a1_dst =
356-
(const struct sockaddr_in6 *)a1->ai->ai_addr;
357+
CARES_INADDR_CAST(const struct sockaddr_in6 *, a1->ai->ai_addr);
357358
const struct sockaddr_in6 *a2_src = &a2->src_addr.sa6;
358359
const struct sockaddr_in6 *a2_dst =
359-
(const struct sockaddr_in6 *)a2->ai->ai_addr;
360+
CARES_INADDR_CAST(const struct sockaddr_in6 *, a2->ai->ai_addr);
360361
prefixlen1 = common_prefix_len(&a1_src->sin6_addr, &a1_dst->sin6_addr);
361362
prefixlen2 = common_prefix_len(&a2_src->sin6_addr, &a2_dst->sin6_addr);
362363
if (prefixlen1 != prefixlen2)
@@ -384,7 +385,7 @@ static int find_src_addr(ares_channel channel,
384385
const struct sockaddr *addr,
385386
struct sockaddr *src_addr)
386387
{
387-
int sock;
388+
ares_socket_t sock;
388389
int ret;
389390
ares_socklen_t len;
390391

@@ -402,7 +403,7 @@ static int find_src_addr(ares_channel channel,
402403
}
403404

404405
sock = ares__open_socket(channel, addr->sa_family, SOCK_DGRAM, IPPROTO_UDP);
405-
if (sock == -1)
406+
if (sock == ARES_SOCKET_BAD)
406407
{
407408
if (errno == EAFNOSUPPORT)
408409
{
@@ -426,7 +427,7 @@ static int find_src_addr(ares_channel channel,
426427
return 0;
427428
}
428429

429-
if (getsockname(sock, src_addr, &len) == -1)
430+
if (getsockname(sock, src_addr, &len) != 0)
430431
{
431432
ares__close_socket(channel, sock);
432433
return -1;
@@ -491,4 +492,4 @@ int ares__sortaddrinfo(ares_channel channel, struct ares_addrinfo_node *list_sen
491492

492493
ares_free(elems);
493494
return ARES_SUCCESS;
494-
}
495+
}

deps/cares/src/ares_getaddrinfo.c

+11
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ static int fake_addrinfo(const char *name,
386386
}
387387
}
388388

389+
node->ai_socktype = hints->ai_socktype;
390+
node->ai_protocol = hints->ai_protocol;
391+
389392
callback(arg, ARES_SUCCESS, 0, ai);
390393
return 1;
391394
}
@@ -406,6 +409,8 @@ static void end_hquery(struct host_query *hquery, int status)
406409
/* Set port into each address (resolved separately). */
407410
while (next)
408411
{
412+
next->ai_socktype = hquery->hints.ai_socktype;
413+
next->ai_protocol = hquery->hints.ai_protocol;
409414
if (next->ai_family == AF_INET)
410415
{
411416
(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr))->sin_port = htons(hquery->port);
@@ -754,12 +759,18 @@ static int as_is_first(const struct host_query* hquery)
754759
{
755760
char* p;
756761
int ndots = 0;
762+
size_t nname = strlen(hquery->name);
757763
for (p = hquery->name; *p; p++)
758764
{
759765
if (*p == '.')
760766
{
761767
ndots++;
762768
}
763769
}
770+
if (nname && hquery->name[nname-1] == '.')
771+
{
772+
/* prevent ARES_EBADNAME for valid FQDN, where ndots < channel->ndots */
773+
return 1;
774+
}
764775
return ndots >= hquery->channel->ndots;
765776
}

deps/cares/src/ares_gethostbyaddr.c

-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ static int file_lookup(struct ares_addr *addr, struct hostent **host)
208208
strcat(PATH_HOSTS, WIN_PATH_HOSTS);
209209

210210
#elif defined(WATT32)
211-
extern const char *_w32_GetHostsFile (void);
212211
const char *PATH_HOSTS = _w32_GetHostsFile();
213212

214213
if (!PATH_HOSTS)

deps/cares/src/ares_gethostbyname.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static int fake_hostent(const char *name, int family,
258258
struct in_addr in;
259259
struct ares_in6_addr in6;
260260

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

284-
if (result)
285-
family = AF_INET;
285+
/*
286+
* Set address family in case of failure,
287+
* as we will try to convert it later afterwards
288+
*/
289+
family = result ? AF_INET : AF_INET6;
286290
}
287291
if (family == AF_INET6)
288292
result = (ares_inet_pton(AF_INET6, name, &in6) < 1 ? 0 : 1);
@@ -383,7 +387,6 @@ static int file_lookup(const char *name, int family, struct hostent **host)
383387
strcat(PATH_HOSTS, WIN_PATH_HOSTS);
384388

385389
#elif defined(WATT32)
386-
extern const char *_w32_GetHostsFile (void);
387390
const char *PATH_HOSTS = _w32_GetHostsFile();
388391

389392
if (!PATH_HOSTS)

deps/cares/src/ares_init.c

+4-16
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,6 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
115115
int status = ARES_SUCCESS;
116116
struct timeval now;
117117

118-
#ifdef CURLDEBUG
119-
const char *env = getenv("CARES_MEMDEBUG");
120-
121-
if (env)
122-
curl_memdebug(env);
123-
env = getenv("CARES_MEMLIMIT");
124-
if (env) {
125-
char *endptr;
126-
long num = strtol(env, &endptr, 10);
127-
if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
128-
curl_memlimit(num);
129-
}
130-
#endif
131-
132118
if (ares_library_initialized() != ARES_SUCCESS)
133119
return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
134120

@@ -1611,7 +1597,8 @@ static int init_by_resolv_conf(ares_channel channel)
16111597
if (channel->nservers == -1) {
16121598
union res_sockaddr_union addr[MAXNS];
16131599
int nscount = res_getservers(&res, addr, MAXNS);
1614-
for (int i = 0; i < nscount; ++i) {
1600+
int i;
1601+
for (i = 0; i < nscount; ++i) {
16151602
char str[INET6_ADDRSTRLEN];
16161603
int config_status;
16171604
sa_family_t family = addr[i].sin.sin_family;
@@ -1639,8 +1626,9 @@ static int init_by_resolv_conf(ares_channel channel)
16391626
if (!channel->domains) {
16401627
status = ARES_ENOMEM;
16411628
} else {
1629+
int i;
16421630
channel->ndomains = entries;
1643-
for (int i = 0; i < channel->ndomains; ++i) {
1631+
for (i = 0; i < channel->ndomains; ++i) {
16441632
channel->domains[i] = ares_strdup(res.dnsrch[i]);
16451633
if (!channel->domains[i])
16461634
status = ARES_ENOMEM;

deps/cares/src/ares_parse_caa_reply.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ ares_parse_caa_reply (const unsigned char *abuf, int alen,
140140
status = ARES_EBADRESP;
141141
break;
142142
}
143-
caa_curr->critical = (int)*strptr++;
143+
caa_curr->critical = (int)*strptr++;
144144
caa_curr->plength = (int)*strptr++;
145145
if (caa_curr->plength <= 0 || (int)caa_curr->plength >= rr_len - 2)
146146
{

deps/cares/src/ares_parse_soa_reply.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
6262
return ARES_EBADRESP;
6363
if (ancount == 0)
6464
return ARES_EBADRESP;
65-
65+
6666
aptr = abuf + HFIXEDSZ;
6767

6868
/* query name */
6969
status = ares__expand_name_for_response(aptr, abuf, alen, &qname, &len);
7070
if (status != ARES_SUCCESS)
7171
goto failed_stat;
72+
73+
if (alen <= len + HFIXEDSZ + 1)
74+
goto failed;
7275
aptr += len;
7376

7477
qclass = DNS_QUESTION_TYPE(aptr);
@@ -161,9 +164,9 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
161164
return ARES_SUCCESS;
162165
}
163166
aptr += rr_len;
164-
167+
165168
ares_free(rr_name);
166-
169+
167170
if (aptr > abuf + alen)
168171
goto failed_stat;
169172
}

deps/cares/src/ares_private.h

+1-9
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#elif defined(WATT32)
7575

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

7879
#elif defined(NETWARE)
7980

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

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

0 commit comments

Comments
 (0)