Skip to content

Commit 5f947db

Browse files
committedAug 11, 2021
deps: update c-ares to 1.17.2
Refs: https://github.com/c-ares/c-ares/releases/tag/cares-1_17_2 CVE-ID: CVE-2021-3672, CVE-2021-22931 Refs: https://nvd.nist.gov/vuln/detail/CVE-2021-3672 Refs: https://nvd.nist.gov/vuln/detail/CVE-2021-22931 PR-URL: #39724 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 42695ea commit 5f947db

39 files changed

+889
-593
lines changed
 

Diff for: ‎deps/cares/RELEASE-NOTES

+66-55
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,79 @@
1-
c-ares version 1.17.1
1+
c-ares version 1.17.2
22

3-
Due to a packaging issue with 1.17.0, we have released 1.17.1 to address that
4-
issue. See 1.17.0 release notes below..
5-
6-
7-
c-ares version 1.17.0
3+
This is a security and bugfix release. It addresses a few security related
4+
issues along with various bugfixes mostly related to portability.
85

96
Security:
10-
o avoid read-heap-buffer-overflow in ares_parse_soa_reply found during
11-
fuzzing [2] [3]
12-
o Avoid theoretical buffer overflow in RC4 loop comparison [5]
13-
o Empty hquery->name could lead to invalid memory access [15]
14-
o ares_parse_{a,aaaa}_reply() could return a larger *naddrttls than was
15-
passed in [17]
7+
o NodeJS passes NULL for addr and 0 for addrlen to ares_parse_ptr_reply() on
8+
systems where malloc(0) returns NULL. This would cause a crash. [8]
9+
o When building c-ares with CMake, the RANDOM_FILE would not be set and
10+
therefore downgrade to the less secure random number generator [12]
11+
o If ares_getaddrinfo() was terminated by an ares_destroy(), it would cause
12+
a crash [13]
13+
o Crash in sortaddrinfo() if the list size equals 0 due to an unexpected
14+
DNS response [14]
15+
o Expand number of escaped characters in DNS replies as per RFC1035 5.1 to
16+
prevent spoofing [16], [17]
17+
o Perform validation on hostnames to prevent possible XSS due to applications
18+
not performing valiation themselves [18]
1619

1720
Changes:
18-
o Update help information for adig, acountry, and ahost [4]
19-
o Test Suite now uses dynamic system-assigned ports rather than hardcoded
20-
ports to prevent failures in containers [10]
21-
o Detect remote DNS server does not support EDNS using rules from RFC 6891 [12]
22-
o Source tree has been reorganized to use a more modern layout [13]
23-
o Allow parsing of CAA Resource Record [14]
21+
o Use non-blocking /dev/urandom for random data to prevent early startup
22+
performance issues [5]
23+
o z/OS port [6]
24+
o ares_malloc(0) is now defined behavior (returns NULL) rather than
25+
system-specific to catch edge cases [7]
2426

2527
Bug fixes:
26-
o readaddrinfo bad sizeof() [1]
27-
o Test cases should honor HAVE_WRITEV flag, not depend on WIN32 [6]
28-
o FQDN with trailing period should be queried first [7]
29-
o ares_getaddrinfo() was returning members of the struct as garbage values if
30-
unset, and was not honoring ai_socktype and ai_protocol hints. [8] [9]
31-
o ares_gethostbyname() with AF_UNSPEC and an ip address would fail [11]
32-
o Properly document ares_set_local_ip4() uses host byte order [16]
28+
o Fuzz testing files were not distributed with official archives [1]
29+
o Building tests should not force building of static libraries except on
30+
Windows [2]
31+
o Windows builds of the tools would fail if built as static due to a missing
32+
CARES_STATICLIB definition [3]
33+
o Relative headers must use double quotes to prevent pulling in a system
34+
library [4]
35+
o Fix OpenBSD building by implementing portability updates for including
36+
arpa/nameser.h [9]
37+
o Fix building out-of-tree for autotools [10]
38+
o Make install on MacOS/iOS with CMake was missing the bundle destination so
39+
libraries weren't actually installed [11]
40+
o Fix retrieving DNS server configuration on MacOS and iOS if the configuration
41+
did not include search domains [15]
42+
o ares_parse_a_reply and ares_parse_aaa_reply were erroneously using strdup()
43+
instead of ares_strdup() [19]
44+
3345

3446
Thanks go to these friendly people for their efforts and contributions:
35-
@anonymoushelpishere
36-
Anthony Penniston (@apenn-msft)
47+
Anton Danielsson (@anton-danielsson)
3748
Brad House (@bradh352)
38-
Bulat Gaifullin (@bgaifullin)
39-
Daniela Sonnenschein (@lxdicted)
4049
Daniel Stenberg (@bagder)
41-
David Hotham (@dimbleby)
42-
Fionn Fitzmaurice (@fionn)
43-
Gisle Vanem (@gavenm)
44-
Ivan Baidakou (@basiliscos)
45-
Jonathan Maye-Hobbs (@wheelpharoah)
46-
Łukasz Marszał (@lmarszal)
47-
lutianxiong (@ltx2018)
48-
Seraphime Kirkovski (@Seraphime)
49-
(14 contributors)
50+
Dhrumil Rana (@dhrumilrana)
51+
František Dvořák (@valtri)
52+
@halx99
53+
Jay Freeman (@saurik)
54+
Jean-pierre Cartal (@jeanpierrecartal)
55+
Michael Kourlas
56+
Philipp Jeitner
57+
@vburdo
58+
(11 contributors)
5059

5160
References to bug reports and discussions on issues:
52-
[1] = https://github.com/c-ares/c-ares/pull/331
53-
[2] = https://github.com/c-ares/c-ares/pull/332
54-
[3] = https://github.com/c-ares/c-ares/issues/333
55-
[4] = https://github.com/c-ares/c-ares/pull/334
56-
[5] = https://github.com/c-ares/c-ares/pull/336
57-
[6] = https://github.com/c-ares/c-ares/pull/344
58-
[7] = https://github.com/c-ares/c-ares/pull/345
59-
[8] = https://github.com/c-ares/c-ares/issues/343
60-
[9] = https://github.com/c-ares/c-ares/issues/317
61-
[10] = https://github.com/c-ares/c-ares/pull/346
62-
[11] = https://github.com/c-ares/c-ares/pull/204
63-
[12] = https://github.com/c-ares/c-ares/pull/244
64-
[13] = https://github.com/c-ares/c-ares/pull/349
65-
[14] = https://github.com/c-ares/c-ares/pull/360
66-
[15] = https://github.com/c-ares/c-ares/pull/367
67-
[16] = https://github.com/c-ares/c-ares/pull/368
68-
[17] = https://github.com/c-ares/c-ares/issues/371
61+
[1] = https://github.com/c-ares/c-ares/issues/379
62+
[2] = https://github.com/c-ares/c-ares/issues/380
63+
[3] = https://github.com/c-ares/c-ares/issues/384
64+
[4] = https://github.com/c-ares/c-ares/pull/386
65+
[5] = https://github.com/c-ares/c-ares/pull/391
66+
[6] = https://github.com/c-ares/c-ares/pull/390
67+
[7] = https://github.com/c-ares/c-ares/commit/485fb66
68+
[8] = https://github.com/c-ares/c-ares/issues/392
69+
[9] = https://github.com/c-ares/c-ares/issues/388
70+
[10] = https://github.com/c-ares/c-ares/pull/394
71+
[11] = https://github.com/c-ares/c-ares/pull/395
72+
[12] = https://github.com/c-ares/c-ares/pull/397
73+
[13] = https://github.com/c-ares/c-ares/commit/df94703
74+
[14] = https://github.com/c-ares/c-ares/pull/400
75+
[15] = https://github.com/c-ares/c-ares/pull/401
76+
[16] = https://github.com/c-ares/c-ares/commit/362f91d
77+
[17] = https://github.com/c-ares/c-ares/commit/44c009b
78+
[18] = https://github.com/c-ares/c-ares/commit/c9b6c60
79+
[19] = https://github.com/c-ares/c-ares/pull/408

Diff for: ‎deps/cares/cares.gyp

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
'src/lib/ares_llist.c',
6767
'src/lib/ares_llist.h',
6868
'src/lib/ares_mkquery.c',
69+
'src/lib/ares_nameser.h',
6970
'src/lib/ares_nowarn.c',
7071
'src/lib/ares_nowarn.h',
7172
'src/lib/ares_options.c',
@@ -106,7 +107,6 @@
106107
'src/lib/inet_net_pton.c',
107108
'src/lib/inet_ntop.c',
108109
'src/lib/ares_inet_net_pton.h',
109-
'src/lib/nameser.h',
110110
'src/lib/setup_once.h',
111111
'src/tools/ares_getopt.c',
112112
'src/tools/ares_getopt.h',

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \
4040
defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \
4141
defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \
42-
defined(__QNXNTO__)
42+
defined(__QNXNTO__) || defined(__MVS__)
4343
#include <sys/select.h>
4444
#endif
4545
#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
#define ARES_VERSION_MAJOR 1
99
#define ARES_VERSION_MINOR 17
10-
#define ARES_VERSION_PATCH 1
10+
#define ARES_VERSION_PATCH 2
1111
#define ARES_VERSION ((ARES_VERSION_MAJOR<<16)|\
1212
(ARES_VERSION_MINOR<<8)|\
1313
(ARES_VERSION_PATCH))
14-
#define ARES_VERSION_STR "1.17.1"
14+
#define ARES_VERSION_STR "1.17.2"
1515

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

Diff for: ‎deps/cares/src/lib/ares__parse_into_addrinfo.c

+5-11
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,8 @@
2424
#ifdef HAVE_ARPA_INET_H
2525
# include <arpa/inet.h>
2626
#endif
27-
#ifdef HAVE_ARPA_NAMESER_H
28-
# include <arpa/nameser.h>
29-
#else
30-
# include "nameser.h"
31-
#endif
32-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
33-
# include <arpa/nameser_compat.h>
34-
#endif
27+
28+
#include "ares_nameser.h"
3529

3630
#ifdef HAVE_STRINGS_H
3731
# include <strings.h>
@@ -76,7 +70,7 @@ int ares__parse_into_addrinfo2(const unsigned char *abuf,
7670

7771
/* Expand the name from the question, and skip past the question. */
7872
aptr = abuf + HFIXEDSZ;
79-
status = ares__expand_name_for_response(aptr, abuf, alen, question_hostname, &len);
73+
status = ares__expand_name_for_response(aptr, abuf, alen, question_hostname, &len, 0);
8074
if (status != ARES_SUCCESS)
8175
return status;
8276
if (aptr + len + QFIXEDSZ > abuf + alen)
@@ -92,7 +86,7 @@ int ares__parse_into_addrinfo2(const unsigned char *abuf,
9286
for (i = 0; i < (int)ancount; i++)
9387
{
9488
/* Decode the RR up to the data field. */
95-
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len);
89+
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len, 0);
9690
if (status != ARES_SUCCESS)
9791
{
9892
rr_name = NULL;
@@ -194,7 +188,7 @@ int ares__parse_into_addrinfo2(const unsigned char *abuf,
194188
{
195189
got_cname = 1;
196190
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data,
197-
&len);
191+
&len, 1);
198192
if (status != ARES_SUCCESS)
199193
{
200194
goto failed_stat;

Diff for: ‎deps/cares/src/lib/ares__sortaddrinfo.c

+4
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ int ares__sortaddrinfo(ares_channel channel, struct ares_addrinfo_node *list_sen
453453
++nelem;
454454
cur = cur->ai_next;
455455
}
456+
457+
if (!nelem)
458+
return ARES_ENODATA;
459+
456460
elems = (struct addrinfo_sort_elem *)ares_malloc(
457461
nelem * sizeof(struct addrinfo_sort_elem));
458462
if (!elems)

Diff for: ‎deps/cares/src/lib/ares_create_query.c

+4-13
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,13 @@
1919
#ifdef HAVE_NETINET_IN_H
2020
# include <netinet/in.h>
2121
#endif
22-
#ifdef HAVE_ARPA_NAMESER_H
23-
# include <arpa/nameser.h>
24-
#else
25-
# include "nameser.h"
26-
#endif
27-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
28-
# include <arpa/nameser_compat.h>
29-
#endif
22+
23+
#include "ares_nameser.h"
3024

3125
#include "ares.h"
3226
#include "ares_dns.h"
3327
#include "ares_private.h"
3428

35-
#ifndef T_OPT
36-
# define T_OPT 41 /* EDNS0 option (meta-RR) */
37-
#endif
3829

3930
/* Header format, from RFC 1035:
4031
* 1 1 1 1 1 1
@@ -57,7 +48,7 @@
5748
* of the remaining fields:
5849
* ID Identifier to match responses with queries
5950
* QR Query (0) or response (1)
60-
* Opcode For our purposes, always QUERY
51+
* Opcode For our purposes, always O_QUERY
6152
* RD Recursion desired
6253
* Z Reserved (zero)
6354
* QDCOUNT Number of queries
@@ -116,7 +107,7 @@ int ares_create_query(const char *name, int dnsclass, int type,
116107
q = buf;
117108
memset(q, 0, HFIXEDSZ);
118109
DNS_HEADER_SET_QID(q, id);
119-
DNS_HEADER_SET_OPCODE(q, QUERY);
110+
DNS_HEADER_SET_OPCODE(q, O_QUERY);
120111
if (rd) {
121112
DNS_HEADER_SET_RD(q, 1);
122113
}

Diff for: ‎deps/cares/src/lib/ares_expand_name.c

+114-23
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@
1919
#ifdef HAVE_NETINET_IN_H
2020
# include <netinet/in.h>
2121
#endif
22-
#ifdef HAVE_ARPA_NAMESER_H
23-
# include <arpa/nameser.h>
24-
#else
25-
# include "nameser.h"
26-
#endif
27-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
28-
# include <arpa/nameser_compat.h>
29-
#endif
22+
23+
#include "ares_nameser.h"
3024

3125
#include "ares.h"
3226
#include "ares_nowarn.h"
@@ -36,7 +30,52 @@
3630
#define MAX_INDIRS 50
3731

3832
static int name_length(const unsigned char *encoded, const unsigned char *abuf,
39-
int alen);
33+
int alen, int is_hostname);
34+
35+
/* Reserved characters for names that need to be escaped */
36+
static int is_reservedch(int ch)
37+
{
38+
switch (ch) {
39+
case '"':
40+
case '.':
41+
case ';':
42+
case '\\':
43+
case '(':
44+
case ')':
45+
case '@':
46+
case '$':
47+
return 1;
48+
default:
49+
break;
50+
}
51+
52+
return 0;
53+
}
54+
55+
static int ares__isprint(int ch)
56+
{
57+
if (ch >= 0x20 && ch <= 0x7E)
58+
return 1;
59+
return 0;
60+
}
61+
62+
/* Character set allowed by hostnames */
63+
static int is_hostnamech(int ch)
64+
{
65+
/* [A-Za-z0-9-.]
66+
* Don't use isalnum() as it is locale-specific
67+
*/
68+
if (ch >= 'A' && ch <= 'Z')
69+
return 1;
70+
if (ch >= 'a' && ch <= 'z')
71+
return 1;
72+
if (ch >= '0' && ch <= '9')
73+
return 1;
74+
if (ch == '-' || ch == '.')
75+
return 1;
76+
77+
return 0;
78+
}
4079

4180
/* Expand an RFC1035-encoded domain name given by encoded. The
4281
* containing message is given by abuf and alen. The result given by
@@ -60,10 +99,15 @@ static int name_length(const unsigned char *encoded, const unsigned char *abuf,
6099
*
61100
* Since the expanded name uses '.' as a label separator, we use
62101
* backslashes to escape periods or backslashes in the expanded name.
102+
*
103+
* If the result is expected to be a hostname, then no escaped data is allowed
104+
* and will return error.
63105
*/
64106

65-
int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
66-
int alen, char **s, long *enclen)
107+
int ares__expand_name_validated(const unsigned char *encoded,
108+
const unsigned char *abuf,
109+
int alen, char **s, long *enclen,
110+
int is_hostname)
67111
{
68112
int len, indir = 0;
69113
char *q;
@@ -73,7 +117,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
73117
size_t uns;
74118
} nlen;
75119

76-
nlen.sig = name_length(encoded, abuf, alen);
120+
nlen.sig = name_length(encoded, abuf, alen, is_hostname);
77121
if (nlen.sig < 0)
78122
return ARES_EBADNAME;
79123

@@ -113,18 +157,36 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
113157
}
114158
else
115159
{
116-
len = *p;
160+
int name_len = *p;
161+
len = name_len;
117162
p++;
163+
118164
while (len--)
119165
{
120-
if (*p == '.' || *p == '\\')
121-
*q++ = '\\';
122-
*q++ = *p;
166+
/* Output as \DDD for consistency with RFC1035 5.1, except
167+
* for the special case of a root name response */
168+
if (!ares__isprint(*p) && !(name_len == 1 && *p == 0))
169+
{
170+
*q++ = '\\';
171+
*q++ = '0' + *p / 100;
172+
*q++ = '0' + (*p % 100) / 10;
173+
*q++ = '0' + (*p % 10);
174+
}
175+
else if (is_reservedch(*p))
176+
{
177+
*q++ = '\\';
178+
*q++ = *p;
179+
}
180+
else
181+
{
182+
*q++ = *p;
183+
}
123184
p++;
124185
}
125186
*q++ = '.';
126187
}
127-
}
188+
}
189+
128190
if (!indir)
129191
*enclen = aresx_uztosl(p + 1U - encoded);
130192

@@ -137,11 +199,18 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
137199
return ARES_SUCCESS;
138200
}
139201

202+
203+
int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
204+
int alen, char **s, long *enclen)
205+
{
206+
return ares__expand_name_validated(encoded, abuf, alen, s, enclen, 0);
207+
}
208+
140209
/* Return the length of the expansion of an encoded domain name, or
141210
* -1 if the encoding is invalid.
142211
*/
143212
static int name_length(const unsigned char *encoded, const unsigned char *abuf,
144-
int alen)
213+
int alen, int is_hostname)
145214
{
146215
int n = 0, offset, indir = 0, top;
147216

@@ -171,15 +240,35 @@ static int name_length(const unsigned char *encoded, const unsigned char *abuf,
171240
}
172241
else if (top == 0x00)
173242
{
174-
offset = *encoded;
243+
int name_len = *encoded;
244+
offset = name_len;
175245
if (encoded + offset + 1 >= abuf + alen)
176246
return -1;
177247
encoded++;
248+
178249
while (offset--)
179250
{
180-
n += (*encoded == '.' || *encoded == '\\') ? 2 : 1;
251+
if (!ares__isprint(*encoded) && !(name_len == 1 && *encoded == 0))
252+
{
253+
if (is_hostname)
254+
return -1;
255+
n += 4;
256+
}
257+
else if (is_reservedch(*encoded))
258+
{
259+
if (is_hostname)
260+
return -1;
261+
n += 2;
262+
}
263+
else
264+
{
265+
if (is_hostname && !is_hostnamech(*encoded))
266+
return -1;
267+
n += 1;
268+
}
181269
encoded++;
182270
}
271+
183272
n++;
184273
}
185274
else
@@ -197,12 +286,14 @@ static int name_length(const unsigned char *encoded, const unsigned char *abuf,
197286
return (n) ? n - 1 : n;
198287
}
199288

200-
/* Like ares_expand_name but returns EBADRESP in case of invalid input. */
289+
/* Like ares_expand_name_validated but returns EBADRESP in case of invalid
290+
* input. */
201291
int ares__expand_name_for_response(const unsigned char *encoded,
202292
const unsigned char *abuf, int alen,
203-
char **s, long *enclen)
293+
char **s, long *enclen, int is_hostname)
204294
{
205-
int status = ares_expand_name(encoded, abuf, alen, s, enclen);
295+
int status = ares__expand_name_validated(encoded, abuf, alen, s, enclen,
296+
is_hostname);
206297
if (status == ARES_EBADNAME)
207298
status = ARES_EBADRESP;
208299
return status;

Diff for: ‎deps/cares/src/lib/ares_expand_string.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@
1919
#ifdef HAVE_NETINET_IN_H
2020
# include <netinet/in.h>
2121
#endif
22-
#ifdef HAVE_ARPA_NAMESER_H
23-
# include <arpa/nameser.h>
24-
#else
25-
# include "nameser.h"
26-
#endif
22+
23+
#include "ares_nameser.h"
2724

2825
#include "ares.h"
2926
#include "ares_private.h" /* for the memdebug */

Diff for: ‎deps/cares/src/lib/ares_free_hostent.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ void ares_free_hostent(struct hostent *host)
3131
return;
3232

3333
ares_free((char *)(host->h_name));
34-
for (p = host->h_aliases; *p; p++)
34+
for (p = host->h_aliases; p && *p; p++)
3535
ares_free(*p);
3636
ares_free(host->h_aliases);
37-
ares_free(host->h_addr_list[0]); /* no matter if there is one or many entries,
38-
there is only one malloc for all of them */
39-
ares_free(host->h_addr_list);
37+
if (host->h_addr_list) {
38+
ares_free(host->h_addr_list[0]); /* no matter if there is one or many entries,
39+
there is only one malloc for all of them */
40+
ares_free(host->h_addr_list);
41+
}
4042
ares_free(host);
4143
}

Diff for: ‎deps/cares/src/lib/ares_freeaddrinfo.c

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ void ares__freeaddrinfo_nodes(struct ares_addrinfo_node *head)
5151

5252
void ares_freeaddrinfo(struct ares_addrinfo *ai)
5353
{
54+
if (ai == NULL)
55+
return;
5456
ares__freeaddrinfo_cnames(ai->cnames);
5557
ares__freeaddrinfo_nodes(ai->nodes);
5658
ares_free(ai);

Diff for: ‎deps/cares/src/lib/ares_getaddrinfo.c

+10-14
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,8 @@
3434
#ifdef HAVE_ARPA_INET_H
3535
# include <arpa/inet.h>
3636
#endif
37-
#ifdef HAVE_ARPA_NAMESER_H
38-
# include <arpa/nameser.h>
39-
#else
40-
# include "nameser.h"
41-
#endif
42-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
43-
# include <arpa/nameser_compat.h>
44-
#endif
37+
38+
#include "ares_nameser.h"
4539

4640
#ifdef HAVE_STRINGS_H
4741
#include <strings.h>
@@ -399,7 +393,7 @@ static void end_hquery(struct host_query *hquery, int status)
399393
struct ares_addrinfo_node *next;
400394
if (status == ARES_SUCCESS)
401395
{
402-
if (!(hquery->hints.ai_flags & ARES_AI_NOSORT))
396+
if (!(hquery->hints.ai_flags & ARES_AI_NOSORT) && hquery->ai->nodes)
403397
{
404398
sentinel.ai_next = hquery->ai->nodes;
405399
ares__sortaddrinfo(hquery->channel, &sentinel);
@@ -550,11 +544,6 @@ static void host_callback(void *arg, int status, int timeouts,
550544
{
551545
addinfostatus = ares__parse_into_addrinfo(abuf, alen, hquery->ai);
552546
}
553-
else if (status == ARES_EDESTRUCTION)
554-
{
555-
end_hquery(hquery, status);
556-
return;
557-
}
558547

559548
if (!hquery->remaining)
560549
{
@@ -572,6 +561,13 @@ static void host_callback(void *arg, int status, int timeouts,
572561
{
573562
next_lookup(hquery, status);
574563
}
564+
else if (status == ARES_EDESTRUCTION)
565+
{
566+
/* NOTE: Could also be ARES_EDESTRUCTION. We need to only call this
567+
* once all queries (there can be multiple for getaddrinfo) are
568+
* terminated. */
569+
end_hquery(hquery, status);
570+
}
575571
else
576572
{
577573
end_hquery(hquery, status);

Diff for: ‎deps/cares/src/lib/ares_gethostbyaddr.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,8 @@
2424
#ifdef HAVE_ARPA_INET_H
2525
# include <arpa/inet.h>
2626
#endif
27-
#ifdef HAVE_ARPA_NAMESER_H
28-
# include <arpa/nameser.h>
29-
#else
30-
# include "nameser.h"
31-
#endif
32-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
33-
# include <arpa/nameser_compat.h>
34-
#endif
27+
28+
#include "ares_nameser.h"
3529

3630
#include "ares.h"
3731
#include "ares_inet_net_pton.h"

Diff for: ‎deps/cares/src/lib/ares_gethostbyname.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,8 @@
2525
#ifdef HAVE_ARPA_INET_H
2626
# include <arpa/inet.h>
2727
#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
28+
29+
#include "ares_nameser.h"
3630

3731
#ifdef HAVE_STRINGS_H
3832
#include <strings.h>

Diff for: ‎deps/cares/src/lib/ares_getnameinfo.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,8 @@
3131
#ifdef HAVE_ARPA_INET_H
3232
# include <arpa/inet.h>
3333
#endif
34-
#ifdef HAVE_ARPA_NAMESER_H
35-
# include <arpa/nameser.h>
36-
#else
37-
# include "nameser.h"
38-
#endif
39-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
40-
# include <arpa/nameser_compat.h>
41-
#endif
34+
35+
#include "ares_nameser.h"
4236

4337
#ifdef HAVE_NET_IF_H
4438
#include <net/if.h>

Diff for: ‎deps/cares/src/lib/ares_init.c

+67-21
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,7 @@
3333
#include <arpa/inet.h>
3434
#endif
3535

36-
#ifdef HAVE_ARPA_NAMESER_H
37-
# include <arpa/nameser.h>
38-
#else
39-
# include "nameser.h"
40-
#endif
41-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
42-
# include <arpa/nameser_compat.h>
43-
#endif
36+
#include "ares_nameser.h"
4437

4538
#if defined(ANDROID) || defined(__ANDROID__)
4639
#include <sys/system_properties.h>
@@ -1472,6 +1465,57 @@ static int init_by_resolv_conf(ares_channel channel)
14721465
/* Catch the case when all the above checks fail (which happens when there
14731466
is no network card or the cable is unplugged) */
14741467
status = ARES_EFILE;
1468+
#elif defined(__MVS__)
1469+
1470+
struct __res_state *res = 0;
1471+
int count4, count6;
1472+
__STATEEXTIPV6 *v6;
1473+
struct server_state *pserver
1474+
if (0 == res) {
1475+
int rc = res_init();
1476+
while (rc == -1 && h_errno == TRY_AGAIN) {
1477+
rc = res_init();
1478+
}
1479+
if (rc == -1) {
1480+
return ARES_ENOMEM;
1481+
}
1482+
res = __res();
1483+
}
1484+
1485+
v6 = res->__res_extIPv6;
1486+
count4 = res->nscount;
1487+
if (v6) {
1488+
count6 = v6->__stat_nscount;
1489+
} else {
1490+
count6 = 0;
1491+
}
1492+
1493+
nservers = count4 + count6;
1494+
servers = ares_malloc(nservers * sizeof(struct server_state));
1495+
if (!servers)
1496+
return ARES_ENOMEM;
1497+
1498+
memset(servers, 0, nservers * sizeof(struct server_state));
1499+
1500+
pserver = servers;
1501+
for (int i = 0; i < count4; ++i, ++pserver) {
1502+
struct sockaddr_in *addr_in = &(res->nsaddr_list[i]);
1503+
pserver->addr.addrV4.s_addr = addr_in->sin_addr.s_addr;
1504+
pserver->addr.family = AF_INET;
1505+
pserver->addr.udp_port = addr_in->sin_port;
1506+
pserver->addr.tcp_port = addr_in->sin_port;
1507+
}
1508+
1509+
for (int j = 0; j < count6; ++j, ++pserver) {
1510+
struct sockaddr_in6 *addr_in = &(v6->__stat_nsaddr_list[j]);
1511+
memcpy(&(pserver->addr.addr.addr6), &(addr_in->sin6_addr),
1512+
sizeof(addr_in->sin6_addr));
1513+
pserver->addr.family = AF_INET6;
1514+
pserver->addr.udp_port = addr_in->sin6_port;
1515+
pserver->addr.tcp_port = addr_in->sin6_port;
1516+
}
1517+
1518+
status = ARES_EOF;
14751519

14761520
#elif defined(__riscos__)
14771521

@@ -1621,17 +1665,18 @@ static int init_by_resolv_conf(ares_channel channel)
16211665
int entries = 0;
16221666
while ((entries < MAXDNSRCH) && res.dnsrch[entries])
16231667
entries++;
1624-
1625-
channel->domains = ares_malloc(entries * sizeof(char *));
1626-
if (!channel->domains) {
1627-
status = ARES_ENOMEM;
1628-
} else {
1629-
int i;
1630-
channel->ndomains = entries;
1631-
for (i = 0; i < channel->ndomains; ++i) {
1632-
channel->domains[i] = ares_strdup(res.dnsrch[i]);
1633-
if (!channel->domains[i])
1634-
status = ARES_ENOMEM;
1668+
if(entries) {
1669+
channel->domains = ares_malloc(entries * sizeof(char *));
1670+
if (!channel->domains) {
1671+
status = ARES_ENOMEM;
1672+
} else {
1673+
int i;
1674+
channel->ndomains = entries;
1675+
for (i = 0; i < channel->ndomains; ++i) {
1676+
channel->domains[i] = ares_strdup(res.dnsrch[i]);
1677+
if (!channel->domains[i])
1678+
status = ARES_ENOMEM;
1679+
}
16351680
}
16361681
}
16371682
}
@@ -2470,9 +2515,10 @@ static void randomize_key(unsigned char* key,int key_data_len)
24702515
randomized = 1;
24712516
}
24722517
#else /* !WIN32 */
2473-
#ifdef RANDOM_FILE
2474-
FILE *f = fopen(RANDOM_FILE, "rb");
2518+
#ifdef CARES_RANDOM_FILE
2519+
FILE *f = fopen(CARES_RANDOM_FILE, "rb");
24752520
if(f) {
2521+
setvbuf(f, NULL, _IONBF, 0);
24762522
counter = aresx_uztosi(fread(key, 1, key_data_len, f));
24772523
fclose(f);
24782524
}

Diff for: ‎deps/cares/src/lib/ares_library_init.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,18 @@ static unsigned int ares_initialized;
4040
static int ares_init_flags;
4141

4242
/* library-private global vars with visibility across the whole library */
43+
44+
/* Some systems may return either NULL or a valid pointer on malloc(0). c-ares should
45+
* never call malloc(0) so lets return NULL so we're more likely to find an issue if it
46+
* were to occur. */
47+
48+
static void *default_malloc(size_t size) { if (size == 0) { return NULL; } return malloc(size); }
49+
4350
#if defined(WIN32)
4451
/* We need indirections to handle Windows DLL rules. */
45-
static void *default_malloc(size_t size) { return malloc(size); }
4652
static void *default_realloc(void *p, size_t size) { return realloc(p, size); }
4753
static void default_free(void *p) { free(p); }
4854
#else
49-
# define default_malloc malloc
5055
# define default_realloc realloc
5156
# define default_free free
5257
#endif

Diff for: ‎deps/cares/src/lib/ares_library_init.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#ifdef USE_WINSOCK
2424

2525
#include <iphlpapi.h>
26-
#include <ares_iphlpapi.h>
26+
#include "ares_iphlpapi.h"
2727

2828
typedef DWORD (WINAPI *fpGetNetworkParams_t) (FIXED_INFO*, DWORD*);
2929
typedef BOOLEAN (APIENTRY *fpSystemFunction036_t) (void*, ULONG);

Diff for: ‎deps/cares/src/lib/ares_nameser.h

+482
Large diffs are not rendered by default.

Diff for: ‎deps/cares/src/lib/ares_parse_a_reply.c

+4-10
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,8 @@
2626
#ifdef HAVE_ARPA_INET_H
2727
# include <arpa/inet.h>
2828
#endif
29-
#ifdef HAVE_ARPA_NAMESER_H
30-
# include <arpa/nameser.h>
31-
#else
32-
# include "nameser.h"
33-
#endif
34-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
35-
# include <arpa/nameser_compat.h>
36-
#endif
29+
30+
#include "ares_nameser.h"
3731

3832
#ifdef HAVE_STRINGS_H
3933
# include <strings.h>
@@ -113,7 +107,7 @@ int ares_parse_a_reply(const unsigned char *abuf, int alen,
113107
while (next_cname)
114108
{
115109
if(next_cname->alias)
116-
aliases[alias++] = strdup(next_cname->alias);
110+
aliases[alias++] = ares_strdup(next_cname->alias);
117111
if(next_cname->ttl < cname_ttl)
118112
cname_ttl = next_cname->ttl;
119113
next_cname = next_cname->next;
@@ -135,7 +129,7 @@ int ares_parse_a_reply(const unsigned char *abuf, int alen,
135129

136130
if (ai.cnames)
137131
{
138-
hostent->h_name = strdup(ai.cnames->name);
132+
hostent->h_name = ares_strdup(ai.cnames->name);
139133
ares_free(question_hostname);
140134
}
141135
else

Diff for: ‎deps/cares/src/lib/ares_parse_aaaa_reply.c

+4-10
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,8 @@
2727
#ifdef HAVE_ARPA_INET_H
2828
# include <arpa/inet.h>
2929
#endif
30-
#ifdef HAVE_ARPA_NAMESER_H
31-
# include <arpa/nameser.h>
32-
#else
33-
# include "nameser.h"
34-
#endif
35-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
36-
# include <arpa/nameser_compat.h>
37-
#endif
30+
31+
#include "ares_nameser.h"
3832

3933
#ifdef HAVE_STRINGS_H
4034
# include <strings.h>
@@ -115,7 +109,7 @@ int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
115109
while (next_cname)
116110
{
117111
if(next_cname->alias)
118-
aliases[alias++] = strdup(next_cname->alias);
112+
aliases[alias++] = ares_strdup(next_cname->alias);
119113
if(next_cname->ttl < cname_ttl)
120114
cname_ttl = next_cname->ttl;
121115
next_cname = next_cname->next;
@@ -137,7 +131,7 @@ int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
137131

138132
if (ai.cnames)
139133
{
140-
hostent->h_name = strdup(ai.cnames->name);
134+
hostent->h_name = ares_strdup(ai.cnames->name);
141135
ares_free(question_hostname);
142136
}
143137
else

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

+2-12
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,8 @@
2525
#ifdef HAVE_ARPA_INET_H
2626
# include <arpa/inet.h>
2727
#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
28+
29+
#include "ares_nameser.h"
3630

3731
#ifdef HAVE_STRINGS_H
3832
# include <strings.h>
@@ -43,10 +37,6 @@
4337
#include "ares_data.h"
4438
#include "ares_private.h"
4539

46-
#ifndef T_CAA
47-
# define T_CAA 257 /* Certification Authority Authorization */
48-
#endif
49-
5040
int
5141
ares_parse_caa_reply (const unsigned char *abuf, int alen,
5242
struct ares_caa_reply **caa_out)

Diff for: ‎deps/cares/src/lib/ares_parse_mx_reply.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,8 @@
2626
#ifdef HAVE_ARPA_INET_H
2727
# include <arpa/inet.h>
2828
#endif
29-
#ifdef HAVE_ARPA_NAMESER_H
30-
# include <arpa/nameser.h>
31-
#else
32-
# include "nameser.h"
33-
#endif
34-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
35-
# include <arpa/nameser_compat.h>
36-
#endif
29+
30+
#include "ares_nameser.h"
3731

3832
#include "ares.h"
3933
#include "ares_dns.h"

Diff for: ‎deps/cares/src/lib/ares_parse_naptr_reply.c

+2-13
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,14 @@
2626
#ifdef HAVE_ARPA_INET_H
2727
# include <arpa/inet.h>
2828
#endif
29-
#ifdef HAVE_ARPA_NAMESER_H
30-
# include <arpa/nameser.h>
31-
#else
32-
# include "nameser.h"
33-
#endif
34-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
35-
# include <arpa/nameser_compat.h>
36-
#endif
29+
30+
#include "ares_nameser.h"
3731

3832
#include "ares.h"
3933
#include "ares_dns.h"
4034
#include "ares_data.h"
4135
#include "ares_private.h"
4236

43-
/* AIX portability check */
44-
#ifndef T_NAPTR
45-
#define T_NAPTR 35 /* naming authority pointer */
46-
#endif
47-
4837
int
4938
ares_parse_naptr_reply (const unsigned char *abuf, int alen,
5039
struct ares_naptr_reply **naptr_out)

Diff for: ‎deps/cares/src/lib/ares_parse_ns_reply.c

+5-11
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,8 @@
2929
#ifdef HAVE_ARPA_INET_H
3030
# include <arpa/inet.h>
3131
#endif
32-
#ifdef HAVE_ARPA_NAMESER_H
33-
# include <arpa/nameser.h>
34-
#else
35-
# include "nameser.h"
36-
#endif
37-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
38-
# include <arpa/nameser_compat.h>
39-
#endif
32+
33+
#include "ares_nameser.h"
4034

4135
#include "ares.h"
4236
#include "ares_dns.h"
@@ -68,7 +62,7 @@ int ares_parse_ns_reply( const unsigned char* abuf, int alen,
6862

6963
/* Expand the name from the question, and skip past the question. */
7064
aptr = abuf + HFIXEDSZ;
71-
status = ares__expand_name_for_response( aptr, abuf, alen, &hostname, &len);
65+
status = ares__expand_name_for_response( aptr, abuf, alen, &hostname, &len, 0);
7266
if ( status != ARES_SUCCESS )
7367
return status;
7468
if ( aptr + len + QFIXEDSZ > abuf + alen )
@@ -91,7 +85,7 @@ int ares_parse_ns_reply( const unsigned char* abuf, int alen,
9185
for ( i = 0; i < ( int ) ancount; i++ )
9286
{
9387
/* Decode the RR up to the data field. */
94-
status = ares__expand_name_for_response( aptr, abuf, alen, &rr_name, &len );
88+
status = ares__expand_name_for_response( aptr, abuf, alen, &rr_name, &len, 0);
9589
if ( status != ARES_SUCCESS )
9690
break;
9791
aptr += len;
@@ -116,7 +110,7 @@ int ares_parse_ns_reply( const unsigned char* abuf, int alen,
116110
{
117111
/* Decode the RR data and add it to the nameservers list */
118112
status = ares__expand_name_for_response( aptr, abuf, alen, &rr_data,
119-
&len);
113+
&len, 1);
120114
if ( status != ARES_SUCCESS )
121115
{
122116
ares_free(rr_name);

Diff for: ‎deps/cares/src/lib/ares_parse_ptr_reply.c

+53-46
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,8 @@
2222
#ifdef HAVE_NETDB_H
2323
# include <netdb.h>
2424
#endif
25-
#ifdef HAVE_ARPA_NAMESER_H
26-
# include <arpa/nameser.h>
27-
#else
28-
# include "nameser.h"
29-
#endif
30-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
31-
# include <arpa/nameser_compat.h>
32-
#endif
25+
26+
#include "ares_nameser.h"
3327

3428
#ifdef HAVE_STRINGS_H
3529
# include <strings.h>
@@ -48,7 +42,7 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
4842
long len;
4943
const unsigned char *aptr;
5044
char *ptrname, *hostname, *rr_name, *rr_data;
51-
struct hostent *hostent;
45+
struct hostent *hostent = NULL;
5246
int aliascnt = 0;
5347
int alias_alloc = 8;
5448
char ** aliases;
@@ -69,7 +63,7 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
6963

7064
/* Expand the name from the question, and skip past the question. */
7165
aptr = abuf + HFIXEDSZ;
72-
status = ares__expand_name_for_response(aptr, abuf, alen, &ptrname, &len);
66+
status = ares__expand_name_for_response(aptr, abuf, alen, &ptrname, &len, 0);
7367
if (status != ARES_SUCCESS)
7468
return status;
7569
if (aptr + len + QFIXEDSZ > abuf + alen)
@@ -90,7 +84,7 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
9084
for (i = 0; i < (int)ancount; i++)
9185
{
9286
/* Decode the RR up to the data field. */
93-
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len);
87+
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len, 0);
9488
if (status != ARES_SUCCESS)
9589
break;
9690
aptr += len;
@@ -116,7 +110,7 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
116110
{
117111
/* Decode the RR data and set hostname to it. */
118112
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data,
119-
&len);
113+
&len, 1);
120114
if (status != ARES_SUCCESS)
121115
{
122116
ares_free(rr_name);
@@ -152,7 +146,7 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
152146
{
153147
/* Decode the RR data and replace ptrname with it. */
154148
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data,
155-
&len);
149+
&len, 1);
156150
if (status != ARES_SUCCESS)
157151
{
158152
ares_free(rr_name);
@@ -175,41 +169,54 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
175169
status = ARES_ENODATA;
176170
if (status == ARES_SUCCESS)
177171
{
178-
/* We got our answer. Allocate memory to build the host entry. */
179-
hostent = ares_malloc(sizeof(struct hostent));
180-
if (hostent)
181-
{
182-
hostent->h_addr_list = ares_malloc(2 * sizeof(char *));
183-
if (hostent->h_addr_list)
184-
{
185-
hostent->h_addr_list[0] = ares_malloc(addrlen);
186-
if (hostent->h_addr_list[0])
187-
{
188-
hostent->h_aliases = ares_malloc((aliascnt+1) * sizeof (char *));
189-
if (hostent->h_aliases)
190-
{
191-
/* Fill in the hostent and return successfully. */
192-
hostent->h_name = hostname;
193-
for (i=0 ; i<aliascnt ; i++)
194-
hostent->h_aliases[i] = aliases[i];
195-
hostent->h_aliases[aliascnt] = NULL;
196-
hostent->h_addrtype = aresx_sitoss(family);
197-
hostent->h_length = aresx_sitoss(addrlen);
198-
memcpy(hostent->h_addr_list[0], addr, addrlen);
199-
hostent->h_addr_list[1] = NULL;
200-
*host = hostent;
201-
ares_free(aliases);
202-
ares_free(ptrname);
203-
return ARES_SUCCESS;
204-
}
205-
ares_free(hostent->h_addr_list[0]);
206-
}
207-
ares_free(hostent->h_addr_list);
208-
}
209-
ares_free(hostent);
210-
}
172+
/* If we don't reach the end, we must have failed due to out of memory */
211173
status = ARES_ENOMEM;
174+
175+
/* We got our answer. Allocate memory to build the host entry. */
176+
hostent = ares_malloc(sizeof(*hostent));
177+
if (!hostent)
178+
goto fail;
179+
180+
/* If we don't memset here, cleanups may fail */
181+
memset(hostent, 0, sizeof(*hostent));
182+
183+
hostent->h_addr_list = ares_malloc(2 * sizeof(char *));
184+
if (!hostent->h_addr_list)
185+
goto fail;
186+
187+
188+
if (addr && addrlen) {
189+
hostent->h_addr_list[0] = ares_malloc(addrlen);
190+
if (!hostent->h_addr_list[0])
191+
goto fail;
192+
} else {
193+
hostent->h_addr_list[0] = NULL;
194+
}
195+
196+
hostent->h_aliases = ares_malloc((aliascnt+1) * sizeof (char *));
197+
if (!hostent->h_aliases)
198+
goto fail;
199+
200+
/* Fill in the hostent and return successfully. */
201+
hostent->h_name = hostname;
202+
for (i=0 ; i<aliascnt ; i++)
203+
hostent->h_aliases[i] = aliases[i];
204+
hostent->h_aliases[aliascnt] = NULL;
205+
hostent->h_addrtype = aresx_sitoss(family);
206+
hostent->h_length = aresx_sitoss(addrlen);
207+
if (addr && addrlen)
208+
memcpy(hostent->h_addr_list[0], addr, addrlen);
209+
hostent->h_addr_list[1] = NULL;
210+
*host = hostent;
211+
ares_free(aliases);
212+
ares_free(ptrname);
213+
214+
return ARES_SUCCESS;
212215
}
216+
217+
fail:
218+
ares_free_hostent(hostent);
219+
213220
for (i=0 ; i<aliascnt ; i++)
214221
if (aliases[i])
215222
ares_free(aliases[i]);

Diff for: ‎deps/cares/src/lib/ares_parse_soa_reply.c

+9-15
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,8 @@
2626
#ifdef HAVE_ARPA_INET_H
2727
# include <arpa/inet.h>
2828
#endif
29-
#ifdef HAVE_ARPA_NAMESER_H
30-
# include <arpa/nameser.h>
31-
#else
32-
# include "nameser.h"
33-
#endif
34-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
35-
# include <arpa/nameser_compat.h>
36-
#endif
29+
30+
#include "ares_nameser.h"
3731

3832
#include "ares.h"
3933
#include "ares_dns.h"
@@ -62,11 +56,11 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
6256
return ARES_EBADRESP;
6357
if (ancount == 0)
6458
return ARES_EBADRESP;
65-
59+
6660
aptr = abuf + HFIXEDSZ;
6761

6862
/* query name */
69-
status = ares__expand_name_for_response(aptr, abuf, alen, &qname, &len);
63+
status = ares__expand_name_for_response(aptr, abuf, alen, &qname, &len, 0);
7064
if (status != ARES_SUCCESS)
7165
goto failed_stat;
7266

@@ -89,7 +83,7 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
8983
for (i = 0; i < ancount; i++)
9084
{
9185
rr_name = NULL;
92-
status = ares__expand_name_for_response (aptr, abuf, alen, &rr_name, &len);
86+
status = ares__expand_name_for_response (aptr, abuf, alen, &rr_name, &len, 0);
9387
if (status != ARES_SUCCESS)
9488
{
9589
ares_free(rr_name);
@@ -126,7 +120,7 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
126120

127121
/* nsname */
128122
status = ares__expand_name_for_response(aptr, abuf, alen, &soa->nsname,
129-
&len);
123+
&len, 0);
130124
if (status != ARES_SUCCESS)
131125
{
132126
ares_free(rr_name);
@@ -136,7 +130,7 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
136130

137131
/* hostmaster */
138132
status = ares__expand_name_for_response(aptr, abuf, alen,
139-
&soa->hostmaster, &len);
133+
&soa->hostmaster, &len, 0);
140134
if (status != ARES_SUCCESS)
141135
{
142136
ares_free(rr_name);
@@ -164,9 +158,9 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
164158
return ARES_SUCCESS;
165159
}
166160
aptr += rr_len;
167-
161+
168162
ares_free(rr_name);
169-
163+
170164
if (aptr > abuf + alen)
171165
goto failed_stat;
172166
}

Diff for: ‎deps/cares/src/lib/ares_parse_srv_reply.c

+2-13
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,14 @@
2626
#ifdef HAVE_ARPA_INET_H
2727
# include <arpa/inet.h>
2828
#endif
29-
#ifdef HAVE_ARPA_NAMESER_H
30-
# include <arpa/nameser.h>
31-
#else
32-
# include "nameser.h"
33-
#endif
34-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
35-
# include <arpa/nameser_compat.h>
36-
#endif
29+
30+
#include "ares_nameser.h"
3731

3832
#include "ares.h"
3933
#include "ares_dns.h"
4034
#include "ares_data.h"
4135
#include "ares_private.h"
4236

43-
/* AIX portability check */
44-
#ifndef T_SRV
45-
# define T_SRV 33 /* server selection */
46-
#endif
47-
4837
int
4938
ares_parse_srv_reply (const unsigned char *abuf, int alen,
5039
struct ares_srv_reply **srv_out)

Diff for: ‎deps/cares/src/lib/ares_parse_txt_reply.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,8 @@
2626
#ifdef HAVE_ARPA_INET_H
2727
# include <arpa/inet.h>
2828
#endif
29-
#ifdef HAVE_ARPA_NAMESER_H
30-
# include <arpa/nameser.h>
31-
#else
32-
# include "nameser.h"
33-
#endif
34-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
35-
# include <arpa/nameser_compat.h>
36-
#endif
29+
30+
#include "ares_nameser.h"
3731

3832
#ifdef HAVE_STRINGS_H
3933
# include <strings.h>

Diff for: ‎deps/cares/src/lib/ares_private.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,13 @@ int ares__read_line(FILE *fp, char **buf, size_t *bufsize);
356356
void ares__free_query(struct query *query);
357357
unsigned short ares__generate_new_id(rc4_key* key);
358358
struct timeval ares__tvnow(void);
359+
int ares__expand_name_validated(const unsigned char *encoded,
360+
const unsigned char *abuf,
361+
int alen, char **s, long *enclen,
362+
int is_hostname);
359363
int ares__expand_name_for_response(const unsigned char *encoded,
360364
const unsigned char *abuf, int alen,
361-
char **s, long *enclen);
365+
char **s, long *enclen, int is_hostname);
362366
void ares__init_servers_state(ares_channel channel);
363367
void ares__destroy_servers_state(ares_channel channel);
364368
int ares__parse_qtype_reply(const unsigned char* abuf, int alen, int* qtype);

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

+2-9
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,8 @@
3232
#ifdef HAVE_ARPA_INET_H
3333
# include <arpa/inet.h>
3434
#endif
35-
#ifdef HAVE_ARPA_NAMESER_H
36-
# include <arpa/nameser.h>
37-
#endif
38-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
39-
# include <arpa/nameser_compat.h>
40-
#endif
4135

42-
#include "nameser.h"
36+
#include "ares_nameser.h"
4337

4438
#ifdef HAVE_STRINGS_H
4539
# include <strings.h>
@@ -611,8 +605,7 @@ static void process_answer(ares_channel channel, unsigned char *abuf,
611605
packetsz = PACKETSZ;
612606
/* If we use EDNS and server answers with FORMERR without an OPT RR, the protocol
613607
* extension is not understood by the responder. We must retry the query
614-
* without EDNS enabled.
615-
*/
608+
* without EDNS enabled. */
616609
if (channel->flags & ARES_FLAG_EDNS)
617610
{
618611
packetsz = channel->ednspsz;

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

+2-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@
1919
#ifdef HAVE_NETINET_IN_H
2020
# include <netinet/in.h>
2121
#endif
22-
#ifdef HAVE_ARPA_NAMESER_H
23-
# include <arpa/nameser.h>
24-
#else
25-
# include "nameser.h"
26-
#endif
27-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
28-
# include <arpa/nameser_compat.h>
29-
#endif
22+
23+
#include "ares_nameser.h"
3024

3125
#include "ares.h"
3226
#include "ares_dns.h"

Diff for: ‎deps/cares/src/lib/ares_send.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@
1919
#ifdef HAVE_NETINET_IN_H
2020
# include <netinet/in.h>
2121
#endif
22-
#ifdef HAVE_ARPA_NAMESER_H
23-
# include <arpa/nameser.h>
24-
#else
25-
# include "nameser.h"
26-
#endif
27-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
28-
# include <arpa/nameser_compat.h>
29-
#endif
22+
23+
#include "ares_nameser.h"
3024

3125
#include "ares.h"
3226
#include "ares_dns.h"

Diff for: ‎deps/cares/src/lib/ares_setup.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,11 @@
178178
/*
179179
* Android does have the arpa/nameser.h header which is detected by configure
180180
* but it appears to be empty with recent NDK r7b / r7c, so we undefine here.
181+
* z/OS does have the arpa/nameser.h header which is detected by configure
182+
* but it is not fully implemented and missing identifiers, so udefine here.
181183
*/
182-
#if (defined(ANDROID) || defined(__ANDROID__)) && defined(HAVE_ARPA_NAMESER_H)
184+
#if (defined(ANDROID) || defined(__ANDROID__) || defined(__MVS__)) && \
185+
defined(HAVE_ARPA_NAMESER_H)
183186
# undef HAVE_ARPA_NAMESER_H
184187
#endif
185188

Diff for: ‎deps/cares/src/lib/ares_strsplit.c

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
* without express or implied warranty.
1414
*/
1515

16+
#if defined(__MVS__)
17+
#include <strings.h>
18+
#endif
19+
1620
#include "ares_setup.h"
1721
#include "ares_strsplit.h"
1822
#include "ares.h"

Diff for: ‎deps/cares/src/lib/inet_net_pton.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,8 @@
2424
#ifdef HAVE_ARPA_INET_H
2525
# include <arpa/inet.h>
2626
#endif
27-
#ifdef HAVE_ARPA_NAMESER_H
28-
# include <arpa/nameser.h>
29-
#else
30-
# include "nameser.h"
31-
#endif
32-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
33-
# include <arpa/nameser_compat.h>
34-
#endif
27+
28+
#include "ares_nameser.h"
3529

3630
#include "ares.h"
3731
#include "ares_ipv6.h"

Diff for: ‎deps/cares/src/lib/inet_ntop.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,8 @@
2323
#ifdef HAVE_ARPA_INET_H
2424
# include <arpa/inet.h>
2525
#endif
26-
#ifdef HAVE_ARPA_NAMESER_H
27-
# include <arpa/nameser.h>
28-
#else
29-
# include "nameser.h"
30-
#endif
31-
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
32-
# include <arpa/nameser_compat.h>
33-
#endif
26+
27+
#include "ares_nameser.h"
3428

3529
#include "ares.h"
3630
#include "ares_ipv6.h"

Diff for: ‎deps/cares/src/lib/nameser.h

-218
This file was deleted.

Diff for: ‎src/cares_wrap.cc

+1-9
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,7 @@
3939
# include <netdb.h>
4040
#endif // __POSIX__
4141

42-
#if defined(__ANDROID__) || \
43-
defined(__MINGW32__) || \
44-
defined(__OpenBSD__) || \
45-
defined(_MSC_VER)
46-
47-
# include <nameser.h>
48-
#else
49-
# include <arpa/nameser.h>
50-
#endif
42+
# include <ares_nameser.h>
5143

5244
// OpenBSD does not define these
5345
#ifndef AI_ALL

0 commit comments

Comments
 (0)
Please sign in to comment.