Skip to content

Commit e11a862

Browse files
lxdictedrichardlau
authored andcommittedJul 26, 2021
deps: update to c-ares 1.17.1
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>
1 parent 39e9cd5 commit e11a862

18 files changed

+386
-54
lines changed
 

Diff for: ‎deps/cares/cares.gyp

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
'src/ares__parse_into_addrinfo.c',
7676
'src/ares_parse_aaaa_reply.c',
7777
'src/ares_parse_a_reply.c',
78+
'src/ares_parse_caa_reply.c',
7879
'src/ares_parse_mx_reply.c',
7980
'src/ares_parse_naptr_reply.c',
8081
'src/ares_parse_ns_reply.c',

Diff for: ‎deps/cares/include/ares.h

+13
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,15 @@ struct ares_addr6ttl {
528528
int ttl;
529529
};
530530

531+
struct ares_caa_reply {
532+
struct ares_caa_reply *next;
533+
int critical;
534+
unsigned char *property;
535+
size_t plength; /* plength excludes null termination */
536+
unsigned char *value;
537+
size_t length; /* length excludes null termination */
538+
};
539+
531540
struct ares_srv_reply {
532541
struct ares_srv_reply *next;
533542
char *host;
@@ -637,6 +646,10 @@ CARES_EXTERN int ares_parse_aaaa_reply(const unsigned char *abuf,
637646
struct ares_addr6ttl *addrttls,
638647
int *naddrttls);
639648

649+
CARES_EXTERN int ares_parse_caa_reply(const unsigned char* abuf,
650+
int alen,
651+
struct ares_caa_reply** caa_out);
652+
640653
CARES_EXTERN int ares_parse_ptr_reply(const unsigned char *abuf,
641654
int alen,
642655
const void *addr,

Diff for: ‎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, <daniel@haxx.se>."
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

Diff for: ‎deps/cares/include/nameser.h

+7
Original file line numberDiff line numberDiff line change
@@ -88,6 +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, /* Certification Authority Authorization. */
9192
ns_t_max = 65536
9293
} ns_type;
9394

@@ -204,8 +205,14 @@ typedef enum __ns_rcode {
204205
#define T_AXFR ns_t_axfr
205206
#define T_MAILB ns_t_mailb
206207
#define T_MAILA ns_t_maila
208+
#define T_CAA ns_t_caa
207209
#define T_ANY ns_t_any
208210

209211
#endif /* HAVE_ARPA_NAMESER_COMPAT_H */
210212

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+
211218
#endif /* ARES_NAMESER_H */

Diff for: ‎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
{

Diff for: ‎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+
}

Diff for: ‎deps/cares/src/ares_data.c

+18
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ void ares_free_data(void *dataptr)
119119
ares_free(ptr->data.soa_reply.hostmaster);
120120
break;
121121

122+
case ARES_DATATYPE_CAA_REPLY:
123+
124+
if (ptr->data.caa_reply.next)
125+
next_data = ptr->data.caa_reply.next;
126+
if (ptr->data.caa_reply.property)
127+
ares_free(ptr->data.caa_reply.property);
128+
if (ptr->data.caa_reply.value)
129+
ares_free(ptr->data.caa_reply.value);
130+
break;
131+
122132
default:
123133
return;
124134
}
@@ -174,6 +184,14 @@ void *ares_malloc_data(ares_datatype type)
174184
ptr->data.txt_reply.length = 0;
175185
break;
176186

187+
case ARES_DATATYPE_CAA_REPLY:
188+
ptr->data.caa_reply.next = NULL;
189+
ptr->data.caa_reply.plength = 0;
190+
ptr->data.caa_reply.property = NULL;
191+
ptr->data.caa_reply.length = 0;
192+
ptr->data.caa_reply.value = NULL;
193+
break;
194+
177195
case ARES_DATATYPE_ADDR_NODE:
178196
ptr->data.addr_node.next = NULL;
179197
ptr->data.addr_node.family = 0;

Diff for: ‎deps/cares/src/ares_data.h

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef enum {
3030
ARES_DATATYPE_OPTIONS, /* struct ares_options */
3131
#endif
3232
ARES_DATATYPE_ADDR_PORT_NODE, /* struct ares_addr_port_node - introduced in 1.11.0 */
33+
ARES_DATATYPE_CAA_REPLY, /* struct ares_caa_reply - introduced in 1.17 */
3334
ARES_DATATYPE_LAST /* not used - introduced in 1.7.0 */
3435
} ares_datatype;
3536

@@ -65,6 +66,7 @@ struct ares_data {
6566
struct ares_mx_reply mx_reply;
6667
struct ares_naptr_reply naptr_reply;
6768
struct ares_soa_reply soa_reply;
69+
struct ares_caa_reply caa_reply;
6870
} data;
6971
};
7072

Diff for: ‎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
}

Diff for: ‎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)

Diff for: ‎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)

Diff for: ‎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;

Diff for: ‎deps/cares/src/ares_parse_caa_reply.c

+209
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
2+
/* Copyright 2020 by <danny.sonnenschein@platynum.ch>
3+
*
4+
* Permission to use, copy, modify, and distribute this
5+
* software and its documentation for any purpose and without
6+
* fee is hereby granted, provided that the above copyright
7+
* notice appear in all copies and that both that copyright
8+
* notice and this permission notice appear in supporting
9+
* documentation, and that the name of M.I.T. not be used in
10+
* advertising or publicity pertaining to distribution of the
11+
* software without specific, written prior permission.
12+
* M.I.T. makes no representations about the suitability of
13+
* this software for any purpose. It is provided "as is"
14+
* without express or implied warranty.
15+
*/
16+
17+
#include "ares_setup.h"
18+
19+
#ifdef HAVE_NETINET_IN_H
20+
# include <netinet/in.h>
21+
#endif
22+
#ifdef HAVE_NETDB_H
23+
# include <netdb.h>
24+
#endif
25+
#ifdef HAVE_ARPA_INET_H
26+
# include <arpa/inet.h>
27+
#endif
28+
#ifdef HAVE_ARPA_NAMESER_H
29+
# include <arpa/nameser.h>
30+
#else
31+
# include "nameser.h"
32+
#endif
33+
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
34+
# include <arpa/nameser_compat.h>
35+
#endif
36+
37+
#ifdef HAVE_STRINGS_H
38+
# include <strings.h>
39+
#endif
40+
41+
#include "ares.h"
42+
#include "ares_dns.h"
43+
#include "ares_data.h"
44+
#include "ares_private.h"
45+
46+
#ifndef T_CAA
47+
# define T_CAA 257 /* Certification Authority Authorization */
48+
#endif
49+
50+
int
51+
ares_parse_caa_reply (const unsigned char *abuf, int alen,
52+
struct ares_caa_reply **caa_out)
53+
{
54+
unsigned int qdcount, ancount, i;
55+
const unsigned char *aptr;
56+
const unsigned char *strptr;
57+
int status, rr_type, rr_class, rr_len;
58+
long len;
59+
char *hostname = NULL, *rr_name = NULL;
60+
struct ares_caa_reply *caa_head = NULL;
61+
struct ares_caa_reply *caa_last = NULL;
62+
struct ares_caa_reply *caa_curr;
63+
64+
/* Set *caa_out to NULL for all failure cases. */
65+
*caa_out = NULL;
66+
67+
/* Give up if abuf doesn't have room for a header. */
68+
if (alen < HFIXEDSZ)
69+
return ARES_EBADRESP;
70+
71+
/* Fetch the question and answer count from the header. */
72+
qdcount = DNS_HEADER_QDCOUNT (abuf);
73+
ancount = DNS_HEADER_ANCOUNT (abuf);
74+
if (qdcount != 1)
75+
return ARES_EBADRESP;
76+
if (ancount == 0)
77+
return ARES_ENODATA;
78+
79+
/* Expand the name from the question, and skip past the question. */
80+
aptr = abuf + HFIXEDSZ;
81+
status = ares_expand_name (aptr, abuf, alen, &hostname, &len);
82+
if (status != ARES_SUCCESS)
83+
return status;
84+
85+
if (aptr + len + QFIXEDSZ > abuf + alen)
86+
{
87+
ares_free (hostname);
88+
return ARES_EBADRESP;
89+
}
90+
aptr += len + QFIXEDSZ;
91+
92+
/* Examine each answer resource record (RR) in turn. */
93+
for (i = 0; i < ancount; i++)
94+
{
95+
/* Decode the RR up to the data field. */
96+
status = ares_expand_name (aptr, abuf, alen, &rr_name, &len);
97+
if (status != ARES_SUCCESS)
98+
{
99+
break;
100+
}
101+
aptr += len;
102+
if (aptr + RRFIXEDSZ > abuf + alen)
103+
{
104+
status = ARES_EBADRESP;
105+
break;
106+
}
107+
rr_type = DNS_RR_TYPE (aptr);
108+
rr_class = DNS_RR_CLASS (aptr);
109+
rr_len = DNS_RR_LEN (aptr);
110+
aptr += RRFIXEDSZ;
111+
if (aptr + rr_len > abuf + alen)
112+
{
113+
status = ARES_EBADRESP;
114+
break;
115+
}
116+
117+
/* Check if we are really looking at a CAA record */
118+
if ((rr_class == C_IN || rr_class == C_CHAOS) && rr_type == T_CAA)
119+
{
120+
strptr = aptr;
121+
122+
/* Allocate storage for this CAA answer appending it to the list */
123+
caa_curr = ares_malloc_data(ARES_DATATYPE_CAA_REPLY);
124+
if (!caa_curr)
125+
{
126+
status = ARES_ENOMEM;
127+
break;
128+
}
129+
if (caa_last)
130+
{
131+
caa_last->next = caa_curr;
132+
}
133+
else
134+
{
135+
caa_head = caa_curr;
136+
}
137+
caa_last = caa_curr;
138+
if (rr_len < 2)
139+
{
140+
status = ARES_EBADRESP;
141+
break;
142+
}
143+
caa_curr->critical = (int)*strptr++;
144+
caa_curr->plength = (int)*strptr++;
145+
if (caa_curr->plength <= 0 || (int)caa_curr->plength >= rr_len - 2)
146+
{
147+
status = ARES_EBADRESP;
148+
break;
149+
}
150+
caa_curr->property = ares_malloc (caa_curr->plength + 1/* Including null byte */);
151+
if (caa_curr->property == NULL)
152+
{
153+
status = ARES_ENOMEM;
154+
break;
155+
}
156+
memcpy ((char *) caa_curr->property, strptr, caa_curr->plength);
157+
/* Make sure we NULL-terminate */
158+
caa_curr->property[caa_curr->plength] = 0;
159+
strptr += caa_curr->plength;
160+
161+
caa_curr->length = rr_len - caa_curr->plength - 2;
162+
if (caa_curr->length <= 0)
163+
{
164+
status = ARES_EBADRESP;
165+
break;
166+
}
167+
caa_curr->value = ares_malloc (caa_curr->length + 1/* Including null byte */);
168+
if (caa_curr->value == NULL)
169+
{
170+
status = ARES_ENOMEM;
171+
break;
172+
}
173+
memcpy ((char *) caa_curr->value, strptr, caa_curr->length);
174+
/* Make sure we NULL-terminate */
175+
caa_curr->value[caa_curr->length] = 0;
176+
}
177+
178+
/* Propagate any failures */
179+
if (status != ARES_SUCCESS)
180+
{
181+
break;
182+
}
183+
184+
/* Don't lose memory in the next iteration */
185+
ares_free (rr_name);
186+
rr_name = NULL;
187+
188+
/* Move on to the next record */
189+
aptr += rr_len;
190+
}
191+
192+
if (hostname)
193+
ares_free (hostname);
194+
if (rr_name)
195+
ares_free (rr_name);
196+
197+
/* clean up on error */
198+
if (status != ARES_SUCCESS)
199+
{
200+
if (caa_head)
201+
ares_free_data (caa_head);
202+
return status;
203+
}
204+
205+
/* everything looks fine, return the data */
206+
*caa_out = caa_head;
207+
208+
return ARES_SUCCESS;
209+
}

Diff for: ‎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
}

Diff for: ‎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 */

Diff for: ‎deps/cares/src/ares_process.c

+84-4
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
#endif
3535
#ifdef HAVE_ARPA_NAMESER_H
3636
# include <arpa/nameser.h>
37-
#else
38-
# include "nameser.h"
3937
#endif
4038
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
4139
# include <arpa/nameser_compat.h>
4240
#endif
4341

42+
#include "nameser.h"
43+
4444
#ifdef HAVE_STRINGS_H
4545
# include <strings.h>
4646
#endif
@@ -87,6 +87,7 @@ static int open_udp_socket(ares_channel channel, struct server_state *server);
8787
static int same_questions(const unsigned char *qbuf, int qlen,
8888
const unsigned char *abuf, int alen);
8989
static int same_address(struct sockaddr *sa, struct ares_addr *aa);
90+
static int has_opt_rr(const unsigned char *abuf, int alen);
9091
static void end_query(ares_channel channel, struct query *query, int status,
9192
unsigned char *abuf, int alen);
9293

@@ -608,14 +609,14 @@ static void process_answer(ares_channel channel, unsigned char *abuf,
608609
return;
609610

610611
packetsz = PACKETSZ;
611-
/* If we use EDNS and server answers with one of these RCODES, the protocol
612+
/* If we use EDNS and server answers with FORMERR without an OPT RR, the protocol
612613
* extension is not understood by the responder. We must retry the query
613614
* without EDNS enabled.
614615
*/
615616
if (channel->flags & ARES_FLAG_EDNS)
616617
{
617618
packetsz = channel->ednspsz;
618-
if (rcode == NOTIMP || rcode == FORMERR || rcode == SERVFAIL)
619+
if (rcode == FORMERR && has_opt_rr(abuf, alen) != 1)
619620
{
620621
int qlen = (query->tcplen - 2) - EDNSFIXEDSZ;
621622
channel->flags ^= ARES_FLAG_EDNS;
@@ -1354,6 +1355,85 @@ static int same_address(struct sockaddr *sa, struct ares_addr *aa)
13541355
return 0; /* different */
13551356
}
13561357

1358+
/* search for an OPT RR in the response */
1359+
static int has_opt_rr(const unsigned char *abuf, int alen)
1360+
{
1361+
unsigned int qdcount, ancount, nscount, arcount, i;
1362+
const unsigned char *aptr;
1363+
int status;
1364+
1365+
if (alen < HFIXEDSZ)
1366+
return -1;
1367+
1368+
/* Parse the answer header. */
1369+
qdcount = DNS_HEADER_QDCOUNT(abuf);
1370+
ancount = DNS_HEADER_ANCOUNT(abuf);
1371+
nscount = DNS_HEADER_NSCOUNT(abuf);
1372+
arcount = DNS_HEADER_ARCOUNT(abuf);
1373+
1374+
aptr = abuf + HFIXEDSZ;
1375+
1376+
/* skip the questions */
1377+
for (i = 0; i < qdcount; i++)
1378+
{
1379+
char* name;
1380+
long len;
1381+
status = ares_expand_name(aptr, abuf, alen, &name, &len);
1382+
if (status != ARES_SUCCESS)
1383+
return -1;
1384+
ares_free_string(name);
1385+
if (aptr + len + QFIXEDSZ > abuf + alen)
1386+
return -1;
1387+
aptr += len + QFIXEDSZ;
1388+
}
1389+
1390+
/* skip the ancount and nscount */
1391+
for (i = 0; i < ancount + nscount; i++)
1392+
{
1393+
char* name;
1394+
long len;
1395+
int dlen;
1396+
status = ares_expand_name(aptr, abuf, alen, &name, &len);
1397+
if (status != ARES_SUCCESS)
1398+
return -1;
1399+
ares_free_string(name);
1400+
if (aptr + len + RRFIXEDSZ > abuf + alen)
1401+
return -1;
1402+
aptr += len;
1403+
dlen = DNS_RR_LEN(aptr);
1404+
aptr += RRFIXEDSZ;
1405+
if (aptr + dlen > abuf + alen)
1406+
return -1;
1407+
aptr += dlen;
1408+
}
1409+
1410+
/* search for rr type (41) - opt */
1411+
for (i = 0; i < arcount; i++)
1412+
{
1413+
char* name;
1414+
long len;
1415+
int dlen;
1416+
status = ares_expand_name(aptr, abuf, alen, &name, &len);
1417+
if (status != ARES_SUCCESS)
1418+
return -1;
1419+
ares_free_string(name);
1420+
if (aptr + len + RRFIXEDSZ > abuf + alen)
1421+
return -1;
1422+
aptr += len;
1423+
1424+
if (DNS_RR_TYPE(aptr) == T_OPT)
1425+
return 1;
1426+
1427+
dlen = DNS_RR_LEN(aptr);
1428+
aptr += RRFIXEDSZ;
1429+
if (aptr + dlen > abuf + alen)
1430+
return -1;
1431+
aptr += dlen;
1432+
}
1433+
1434+
return 0;
1435+
}
1436+
13571437
static void end_query (ares_channel channel, struct query *query, int status,
13581438
unsigned char *abuf, int alen)
13591439
{

Diff for: ‎deps/cares/src/ares_query.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void rc4(rc4_key* key, unsigned char *buffer_ptr, int buffer_len)
4545
unsigned char y;
4646
unsigned char* state;
4747
unsigned char xorIndex;
48-
short counter;
48+
int counter;
4949

5050
x = key->x;
5151
y = key->y;

Diff for: ‎deps/cares/src/ares_strsplit.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ void ares_strsplit_free(char **elms, size_t num_elm);
4040

4141

4242
#endif /* HEADER_CARES_STRSPLIT_H */
43+

0 commit comments

Comments
 (0)
Please sign in to comment.