Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeth Griggs <bgriggs@redhat.com>2021-08-10 12:10:09 +0300
committerBeth Griggs <bgriggs@redhat.com>2021-08-11 03:00:08 +0300
commit5f947db68ce3be4339e27fc68ec81a6956ef065f (patch)
treec2c14a960bdd2395cde9e7e6a494c824e9a36ec5
parent42695ea34b3c5bed47e22664b46a0dbdbb721301 (diff)
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: https://github.com/nodejs/node/pull/39724 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
-rw-r--r--deps/cares/RELEASE-NOTES121
-rw-r--r--deps/cares/cares.gyp2
-rw-r--r--deps/cares/include/ares.h2
-rw-r--r--deps/cares/include/ares_version.h4
-rw-r--r--deps/cares/src/lib/ares__parse_into_addrinfo.c16
-rw-r--r--deps/cares/src/lib/ares__sortaddrinfo.c4
-rw-r--r--deps/cares/src/lib/ares_create_query.c17
-rw-r--r--deps/cares/src/lib/ares_expand_name.c137
-rw-r--r--deps/cares/src/lib/ares_expand_string.c7
-rw-r--r--deps/cares/src/lib/ares_free_hostent.c10
-rw-r--r--deps/cares/src/lib/ares_freeaddrinfo.c2
-rw-r--r--deps/cares/src/lib/ares_getaddrinfo.c24
-rw-r--r--deps/cares/src/lib/ares_gethostbyaddr.c10
-rw-r--r--deps/cares/src/lib/ares_gethostbyname.c10
-rw-r--r--deps/cares/src/lib/ares_getnameinfo.c10
-rw-r--r--deps/cares/src/lib/ares_init.c88
-rw-r--r--deps/cares/src/lib/ares_library_init.c9
-rw-r--r--deps/cares/src/lib/ares_library_init.h2
-rw-r--r--deps/cares/src/lib/ares_nameser.h482
-rw-r--r--deps/cares/src/lib/ares_parse_a_reply.c14
-rw-r--r--deps/cares/src/lib/ares_parse_aaaa_reply.c14
-rw-r--r--deps/cares/src/lib/ares_parse_caa_reply.c14
-rw-r--r--deps/cares/src/lib/ares_parse_mx_reply.c10
-rw-r--r--deps/cares/src/lib/ares_parse_naptr_reply.c15
-rw-r--r--deps/cares/src/lib/ares_parse_ns_reply.c16
-rw-r--r--deps/cares/src/lib/ares_parse_ptr_reply.c99
-rw-r--r--deps/cares/src/lib/ares_parse_soa_reply.c24
-rw-r--r--deps/cares/src/lib/ares_parse_srv_reply.c15
-rw-r--r--deps/cares/src/lib/ares_parse_txt_reply.c10
-rw-r--r--deps/cares/src/lib/ares_private.h6
-rw-r--r--deps/cares/src/lib/ares_process.c11
-rw-r--r--deps/cares/src/lib/ares_query.c10
-rw-r--r--deps/cares/src/lib/ares_send.c10
-rw-r--r--deps/cares/src/lib/ares_setup.h5
-rw-r--r--deps/cares/src/lib/ares_strsplit.c4
-rw-r--r--deps/cares/src/lib/inet_net_pton.c10
-rw-r--r--deps/cares/src/lib/inet_ntop.c10
-rw-r--r--deps/cares/src/lib/nameser.h218
-rw-r--r--src/cares_wrap.cc10
39 files changed, 889 insertions, 593 deletions
diff --git a/deps/cares/RELEASE-NOTES b/deps/cares/RELEASE-NOTES
index e1885425ae3..a006ed4c964 100644
--- a/deps/cares/RELEASE-NOTES
+++ b/deps/cares/RELEASE-NOTES
@@ -1,68 +1,79 @@
-c-ares version 1.17.1
+c-ares version 1.17.2
-Due to a packaging issue with 1.17.0, we have released 1.17.1 to address that
-issue. See 1.17.0 release notes below..
-
-
-c-ares version 1.17.0
+This is a security and bugfix release. It addresses a few security related
+issues along with various bugfixes mostly related to portability.
Security:
- o avoid read-heap-buffer-overflow in ares_parse_soa_reply found during
- fuzzing [2] [3]
- o Avoid theoretical buffer overflow in RC4 loop comparison [5]
- o Empty hquery->name could lead to invalid memory access [15]
- o ares_parse_{a,aaaa}_reply() could return a larger *naddrttls than was
- passed in [17]
+ o NodeJS passes NULL for addr and 0 for addrlen to ares_parse_ptr_reply() on
+ systems where malloc(0) returns NULL. This would cause a crash. [8]
+ o When building c-ares with CMake, the RANDOM_FILE would not be set and
+ therefore downgrade to the less secure random number generator [12]
+ o If ares_getaddrinfo() was terminated by an ares_destroy(), it would cause
+ a crash [13]
+ o Crash in sortaddrinfo() if the list size equals 0 due to an unexpected
+ DNS response [14]
+ o Expand number of escaped characters in DNS replies as per RFC1035 5.1 to
+ prevent spoofing [16], [17]
+ o Perform validation on hostnames to prevent possible XSS due to applications
+ not performing valiation themselves [18]
Changes:
- o Update help information for adig, acountry, and ahost [4]
- o Test Suite now uses dynamic system-assigned ports rather than hardcoded
- ports to prevent failures in containers [10]
- o Detect remote DNS server does not support EDNS using rules from RFC 6891 [12]
- o Source tree has been reorganized to use a more modern layout [13]
- o Allow parsing of CAA Resource Record [14]
+ o Use non-blocking /dev/urandom for random data to prevent early startup
+ performance issues [5]
+ o z/OS port [6]
+ o ares_malloc(0) is now defined behavior (returns NULL) rather than
+ system-specific to catch edge cases [7]
Bug fixes:
- o readaddrinfo bad sizeof() [1]
- o Test cases should honor HAVE_WRITEV flag, not depend on WIN32 [6]
- o FQDN with trailing period should be queried first [7]
- o ares_getaddrinfo() was returning members of the struct as garbage values if
- unset, and was not honoring ai_socktype and ai_protocol hints. [8] [9]
- o ares_gethostbyname() with AF_UNSPEC and an ip address would fail [11]
- o Properly document ares_set_local_ip4() uses host byte order [16]
+ o Fuzz testing files were not distributed with official archives [1]
+ o Building tests should not force building of static libraries except on
+ Windows [2]
+ o Windows builds of the tools would fail if built as static due to a missing
+ CARES_STATICLIB definition [3]
+ o Relative headers must use double quotes to prevent pulling in a system
+ library [4]
+ o Fix OpenBSD building by implementing portability updates for including
+ arpa/nameser.h [9]
+ o Fix building out-of-tree for autotools [10]
+ o Make install on MacOS/iOS with CMake was missing the bundle destination so
+ libraries weren't actually installed [11]
+ o Fix retrieving DNS server configuration on MacOS and iOS if the configuration
+ did not include search domains [15]
+ o ares_parse_a_reply and ares_parse_aaa_reply were erroneously using strdup()
+ instead of ares_strdup() [19]
+
Thanks go to these friendly people for their efforts and contributions:
- @anonymoushelpishere
- Anthony Penniston (@apenn-msft)
+ Anton Danielsson (@anton-danielsson)
Brad House (@bradh352)
- Bulat Gaifullin (@bgaifullin)
- Daniela Sonnenschein (@lxdicted)
Daniel Stenberg (@bagder)
- David Hotham (@dimbleby)
- Fionn Fitzmaurice (@fionn)
- Gisle Vanem (@gavenm)
- Ivan Baidakou (@basiliscos)
- Jonathan Maye-Hobbs (@wheelpharoah)
- Łukasz Marszał (@lmarszal)
- lutianxiong (@ltx2018)
- Seraphime Kirkovski (@Seraphime)
-(14 contributors)
+ Dhrumil Rana (@dhrumilrana)
+ František Dvořák (@valtri)
+ @halx99
+ Jay Freeman (@saurik)
+ Jean-pierre Cartal (@jeanpierrecartal)
+ Michael Kourlas
+ Philipp Jeitner
+ @vburdo
+(11 contributors)
References to bug reports and discussions on issues:
- [1] = https://github.com/c-ares/c-ares/pull/331
- [2] = https://github.com/c-ares/c-ares/pull/332
- [3] = https://github.com/c-ares/c-ares/issues/333
- [4] = https://github.com/c-ares/c-ares/pull/334
- [5] = https://github.com/c-ares/c-ares/pull/336
- [6] = https://github.com/c-ares/c-ares/pull/344
- [7] = https://github.com/c-ares/c-ares/pull/345
- [8] = https://github.com/c-ares/c-ares/issues/343
- [9] = https://github.com/c-ares/c-ares/issues/317
- [10] = https://github.com/c-ares/c-ares/pull/346
- [11] = https://github.com/c-ares/c-ares/pull/204
- [12] = https://github.com/c-ares/c-ares/pull/244
- [13] = https://github.com/c-ares/c-ares/pull/349
- [14] = https://github.com/c-ares/c-ares/pull/360
- [15] = https://github.com/c-ares/c-ares/pull/367
- [16] = https://github.com/c-ares/c-ares/pull/368
- [17] = https://github.com/c-ares/c-ares/issues/371
+ [1] = https://github.com/c-ares/c-ares/issues/379
+ [2] = https://github.com/c-ares/c-ares/issues/380
+ [3] = https://github.com/c-ares/c-ares/issues/384
+ [4] = https://github.com/c-ares/c-ares/pull/386
+ [5] = https://github.com/c-ares/c-ares/pull/391
+ [6] = https://github.com/c-ares/c-ares/pull/390
+ [7] = https://github.com/c-ares/c-ares/commit/485fb66
+ [8] = https://github.com/c-ares/c-ares/issues/392
+ [9] = https://github.com/c-ares/c-ares/issues/388
+ [10] = https://github.com/c-ares/c-ares/pull/394
+ [11] = https://github.com/c-ares/c-ares/pull/395
+ [12] = https://github.com/c-ares/c-ares/pull/397
+ [13] = https://github.com/c-ares/c-ares/commit/df94703
+ [14] = https://github.com/c-ares/c-ares/pull/400
+ [15] = https://github.com/c-ares/c-ares/pull/401
+ [16] = https://github.com/c-ares/c-ares/commit/362f91d
+ [17] = https://github.com/c-ares/c-ares/commit/44c009b
+ [18] = https://github.com/c-ares/c-ares/commit/c9b6c60
+ [19] = https://github.com/c-ares/c-ares/pull/408
diff --git a/deps/cares/cares.gyp b/deps/cares/cares.gyp
index 15673e2375f..6c12fc5948d 100644
--- a/deps/cares/cares.gyp
+++ b/deps/cares/cares.gyp
@@ -66,6 +66,7 @@
'src/lib/ares_llist.c',
'src/lib/ares_llist.h',
'src/lib/ares_mkquery.c',
+ 'src/lib/ares_nameser.h',
'src/lib/ares_nowarn.c',
'src/lib/ares_nowarn.h',
'src/lib/ares_options.c',
@@ -106,7 +107,6 @@
'src/lib/inet_net_pton.c',
'src/lib/inet_ntop.c',
'src/lib/ares_inet_net_pton.h',
- 'src/lib/nameser.h',
'src/lib/setup_once.h',
'src/tools/ares_getopt.c',
'src/tools/ares_getopt.h',
diff --git a/deps/cares/include/ares.h b/deps/cares/include/ares.h
index 70a1baf7d71..b341d60934d 100644
--- a/deps/cares/include/ares.h
+++ b/deps/cares/include/ares.h
@@ -39,7 +39,7 @@
#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \
defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \
defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \
- defined(__QNXNTO__)
+ defined(__QNXNTO__) || defined(__MVS__)
#include <sys/select.h>
#endif
#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
diff --git a/deps/cares/include/ares_version.h b/deps/cares/include/ares_version.h
index 0bee17dfe64..de1ac8424cc 100644
--- a/deps/cares/include/ares_version.h
+++ b/deps/cares/include/ares_version.h
@@ -7,11 +7,11 @@
#define ARES_VERSION_MAJOR 1
#define ARES_VERSION_MINOR 17
-#define ARES_VERSION_PATCH 1
+#define ARES_VERSION_PATCH 2
#define ARES_VERSION ((ARES_VERSION_MAJOR<<16)|\
(ARES_VERSION_MINOR<<8)|\
(ARES_VERSION_PATCH))
-#define ARES_VERSION_STR "1.17.1"
+#define ARES_VERSION_STR "1.17.2"
#if (ARES_VERSION >= 0x010700)
# define CARES_HAVE_ARES_LIBRARY_INIT 1
diff --git a/deps/cares/src/lib/ares__parse_into_addrinfo.c b/deps/cares/src/lib/ares__parse_into_addrinfo.c
index b0801632b40..7550abab4a4 100644
--- a/deps/cares/src/lib/ares__parse_into_addrinfo.c
+++ b/deps/cares/src/lib/ares__parse_into_addrinfo.c
@@ -24,14 +24,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#ifdef HAVE_STRINGS_H
# include <strings.h>
@@ -76,7 +70,7 @@ int ares__parse_into_addrinfo2(const unsigned char *abuf,
/* Expand the name from the question, and skip past the question. */
aptr = abuf + HFIXEDSZ;
- status = ares__expand_name_for_response(aptr, abuf, alen, question_hostname, &len);
+ status = ares__expand_name_for_response(aptr, abuf, alen, question_hostname, &len, 0);
if (status != ARES_SUCCESS)
return status;
if (aptr + len + QFIXEDSZ > abuf + alen)
@@ -92,7 +86,7 @@ int ares__parse_into_addrinfo2(const unsigned char *abuf,
for (i = 0; i < (int)ancount; i++)
{
/* Decode the RR up to the data field. */
- status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len);
+ status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len, 0);
if (status != ARES_SUCCESS)
{
rr_name = NULL;
@@ -194,7 +188,7 @@ int ares__parse_into_addrinfo2(const unsigned char *abuf,
{
got_cname = 1;
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data,
- &len);
+ &len, 1);
if (status != ARES_SUCCESS)
{
goto failed_stat;
diff --git a/deps/cares/src/lib/ares__sortaddrinfo.c b/deps/cares/src/lib/ares__sortaddrinfo.c
index 0ad3a5bd98b..6e56cc90230 100644
--- a/deps/cares/src/lib/ares__sortaddrinfo.c
+++ b/deps/cares/src/lib/ares__sortaddrinfo.c
@@ -453,6 +453,10 @@ int ares__sortaddrinfo(ares_channel channel, struct ares_addrinfo_node *list_sen
++nelem;
cur = cur->ai_next;
}
+
+ if (!nelem)
+ return ARES_ENODATA;
+
elems = (struct addrinfo_sort_elem *)ares_malloc(
nelem * sizeof(struct addrinfo_sort_elem));
if (!elems)
diff --git a/deps/cares/src/lib/ares_create_query.c b/deps/cares/src/lib/ares_create_query.c
index 9efce17cfa3..e3d874b4509 100644
--- a/deps/cares/src/lib/ares_create_query.c
+++ b/deps/cares/src/lib/ares_create_query.c
@@ -19,22 +19,13 @@
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#include "ares.h"
#include "ares_dns.h"
#include "ares_private.h"
-#ifndef T_OPT
-# define T_OPT 41 /* EDNS0 option (meta-RR) */
-#endif
/* Header format, from RFC 1035:
* 1 1 1 1 1 1
@@ -57,7 +48,7 @@
* of the remaining fields:
* ID Identifier to match responses with queries
* QR Query (0) or response (1)
- * Opcode For our purposes, always QUERY
+ * Opcode For our purposes, always O_QUERY
* RD Recursion desired
* Z Reserved (zero)
* QDCOUNT Number of queries
@@ -116,7 +107,7 @@ int ares_create_query(const char *name, int dnsclass, int type,
q = buf;
memset(q, 0, HFIXEDSZ);
DNS_HEADER_SET_QID(q, id);
- DNS_HEADER_SET_OPCODE(q, QUERY);
+ DNS_HEADER_SET_OPCODE(q, O_QUERY);
if (rd) {
DNS_HEADER_SET_RD(q, 1);
}
diff --git a/deps/cares/src/lib/ares_expand_name.c b/deps/cares/src/lib/ares_expand_name.c
index 3a38e6737e9..a62c982e045 100644
--- a/deps/cares/src/lib/ares_expand_name.c
+++ b/deps/cares/src/lib/ares_expand_name.c
@@ -19,14 +19,8 @@
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#include "ares.h"
#include "ares_nowarn.h"
@@ -36,7 +30,52 @@
#define MAX_INDIRS 50
static int name_length(const unsigned char *encoded, const unsigned char *abuf,
- int alen);
+ int alen, int is_hostname);
+
+/* Reserved characters for names that need to be escaped */
+static int is_reservedch(int ch)
+{
+ switch (ch) {
+ case '"':
+ case '.':
+ case ';':
+ case '\\':
+ case '(':
+ case ')':
+ case '@':
+ case '$':
+ return 1;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+static int ares__isprint(int ch)
+{
+ if (ch >= 0x20 && ch <= 0x7E)
+ return 1;
+ return 0;
+}
+
+/* Character set allowed by hostnames */
+static int is_hostnamech(int ch)
+{
+ /* [A-Za-z0-9-.]
+ * Don't use isalnum() as it is locale-specific
+ */
+ if (ch >= 'A' && ch <= 'Z')
+ return 1;
+ if (ch >= 'a' && ch <= 'z')
+ return 1;
+ if (ch >= '0' && ch <= '9')
+ return 1;
+ if (ch == '-' || ch == '.')
+ return 1;
+
+ return 0;
+}
/* Expand an RFC1035-encoded domain name given by encoded. The
* 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,
*
* Since the expanded name uses '.' as a label separator, we use
* backslashes to escape periods or backslashes in the expanded name.
+ *
+ * If the result is expected to be a hostname, then no escaped data is allowed
+ * and will return error.
*/
-int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
- int alen, char **s, long *enclen)
+int ares__expand_name_validated(const unsigned char *encoded,
+ const unsigned char *abuf,
+ int alen, char **s, long *enclen,
+ int is_hostname)
{
int len, indir = 0;
char *q;
@@ -73,7 +117,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
size_t uns;
} nlen;
- nlen.sig = name_length(encoded, abuf, alen);
+ nlen.sig = name_length(encoded, abuf, alen, is_hostname);
if (nlen.sig < 0)
return ARES_EBADNAME;
@@ -113,18 +157,36 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
}
else
{
- len = *p;
+ int name_len = *p;
+ len = name_len;
p++;
+
while (len--)
{
- if (*p == '.' || *p == '\\')
- *q++ = '\\';
- *q++ = *p;
+ /* Output as \DDD for consistency with RFC1035 5.1, except
+ * for the special case of a root name response */
+ if (!ares__isprint(*p) && !(name_len == 1 && *p == 0))
+ {
+ *q++ = '\\';
+ *q++ = '0' + *p / 100;
+ *q++ = '0' + (*p % 100) / 10;
+ *q++ = '0' + (*p % 10);
+ }
+ else if (is_reservedch(*p))
+ {
+ *q++ = '\\';
+ *q++ = *p;
+ }
+ else
+ {
+ *q++ = *p;
+ }
p++;
}
*q++ = '.';
}
- }
+ }
+
if (!indir)
*enclen = aresx_uztosl(p + 1U - encoded);
@@ -137,11 +199,18 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
return ARES_SUCCESS;
}
+
+int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
+ int alen, char **s, long *enclen)
+{
+ return ares__expand_name_validated(encoded, abuf, alen, s, enclen, 0);
+}
+
/* Return the length of the expansion of an encoded domain name, or
* -1 if the encoding is invalid.
*/
static int name_length(const unsigned char *encoded, const unsigned char *abuf,
- int alen)
+ int alen, int is_hostname)
{
int n = 0, offset, indir = 0, top;
@@ -171,15 +240,35 @@ static int name_length(const unsigned char *encoded, const unsigned char *abuf,
}
else if (top == 0x00)
{
- offset = *encoded;
+ int name_len = *encoded;
+ offset = name_len;
if (encoded + offset + 1 >= abuf + alen)
return -1;
encoded++;
+
while (offset--)
{
- n += (*encoded == '.' || *encoded == '\\') ? 2 : 1;
+ if (!ares__isprint(*encoded) && !(name_len == 1 && *encoded == 0))
+ {
+ if (is_hostname)
+ return -1;
+ n += 4;
+ }
+ else if (is_reservedch(*encoded))
+ {
+ if (is_hostname)
+ return -1;
+ n += 2;
+ }
+ else
+ {
+ if (is_hostname && !is_hostnamech(*encoded))
+ return -1;
+ n += 1;
+ }
encoded++;
}
+
n++;
}
else
@@ -197,12 +286,14 @@ static int name_length(const unsigned char *encoded, const unsigned char *abuf,
return (n) ? n - 1 : n;
}
-/* Like ares_expand_name but returns EBADRESP in case of invalid input. */
+/* Like ares_expand_name_validated but returns EBADRESP in case of invalid
+ * input. */
int ares__expand_name_for_response(const unsigned char *encoded,
const unsigned char *abuf, int alen,
- char **s, long *enclen)
+ char **s, long *enclen, int is_hostname)
{
- int status = ares_expand_name(encoded, abuf, alen, s, enclen);
+ int status = ares__expand_name_validated(encoded, abuf, alen, s, enclen,
+ is_hostname);
if (status == ARES_EBADNAME)
status = ARES_EBADRESP;
return status;
diff --git a/deps/cares/src/lib/ares_expand_string.c b/deps/cares/src/lib/ares_expand_string.c
index d35df752486..03e39299752 100644
--- a/deps/cares/src/lib/ares_expand_string.c
+++ b/deps/cares/src/lib/ares_expand_string.c
@@ -19,11 +19,8 @@
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
+
+#include "ares_nameser.h"
#include "ares.h"
#include "ares_private.h" /* for the memdebug */
diff --git a/deps/cares/src/lib/ares_free_hostent.c b/deps/cares/src/lib/ares_free_hostent.c
index cfc5f81feb8..ea28ff0e2c1 100644
--- a/deps/cares/src/lib/ares_free_hostent.c
+++ b/deps/cares/src/lib/ares_free_hostent.c
@@ -31,11 +31,13 @@ void ares_free_hostent(struct hostent *host)
return;
ares_free((char *)(host->h_name));
- for (p = host->h_aliases; *p; p++)
+ for (p = host->h_aliases; p && *p; p++)
ares_free(*p);
ares_free(host->h_aliases);
- ares_free(host->h_addr_list[0]); /* no matter if there is one or many entries,
- there is only one malloc for all of them */
- ares_free(host->h_addr_list);
+ if (host->h_addr_list) {
+ ares_free(host->h_addr_list[0]); /* no matter if there is one or many entries,
+ there is only one malloc for all of them */
+ ares_free(host->h_addr_list);
+ }
ares_free(host);
}
diff --git a/deps/cares/src/lib/ares_freeaddrinfo.c b/deps/cares/src/lib/ares_freeaddrinfo.c
index 128f5daec4d..d8891bbf8a5 100644
--- a/deps/cares/src/lib/ares_freeaddrinfo.c
+++ b/deps/cares/src/lib/ares_freeaddrinfo.c
@@ -51,6 +51,8 @@ void ares__freeaddrinfo_nodes(struct ares_addrinfo_node *head)
void ares_freeaddrinfo(struct ares_addrinfo *ai)
{
+ if (ai == NULL)
+ return;
ares__freeaddrinfo_cnames(ai->cnames);
ares__freeaddrinfo_nodes(ai->nodes);
ares_free(ai);
diff --git a/deps/cares/src/lib/ares_getaddrinfo.c b/deps/cares/src/lib/ares_getaddrinfo.c
index ecd5dd5112c..db17a670868 100644
--- a/deps/cares/src/lib/ares_getaddrinfo.c
+++ b/deps/cares/src/lib/ares_getaddrinfo.c
@@ -34,14 +34,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#ifdef HAVE_STRINGS_H
#include <strings.h>
@@ -399,7 +393,7 @@ static void end_hquery(struct host_query *hquery, int status)
struct ares_addrinfo_node *next;
if (status == ARES_SUCCESS)
{
- if (!(hquery->hints.ai_flags & ARES_AI_NOSORT))
+ if (!(hquery->hints.ai_flags & ARES_AI_NOSORT) && hquery->ai->nodes)
{
sentinel.ai_next = hquery->ai->nodes;
ares__sortaddrinfo(hquery->channel, &sentinel);
@@ -550,11 +544,6 @@ static void host_callback(void *arg, int status, int timeouts,
{
addinfostatus = ares__parse_into_addrinfo(abuf, alen, hquery->ai);
}
- else if (status == ARES_EDESTRUCTION)
- {
- end_hquery(hquery, status);
- return;
- }
if (!hquery->remaining)
{
@@ -572,6 +561,13 @@ static void host_callback(void *arg, int status, int timeouts,
{
next_lookup(hquery, status);
}
+ else if (status == ARES_EDESTRUCTION)
+ {
+ /* NOTE: Could also be ARES_EDESTRUCTION. We need to only call this
+ * once all queries (there can be multiple for getaddrinfo) are
+ * terminated. */
+ end_hquery(hquery, status);
+ }
else
{
end_hquery(hquery, status);
diff --git a/deps/cares/src/lib/ares_gethostbyaddr.c b/deps/cares/src/lib/ares_gethostbyaddr.c
index 54eb5997392..c62d230d96e 100644
--- a/deps/cares/src/lib/ares_gethostbyaddr.c
+++ b/deps/cares/src/lib/ares_gethostbyaddr.c
@@ -24,14 +24,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#include "ares.h"
#include "ares_inet_net_pton.h"
diff --git a/deps/cares/src/lib/ares_gethostbyname.c b/deps/cares/src/lib/ares_gethostbyname.c
index 4e41898496f..e09363632ee 100644
--- a/deps/cares/src/lib/ares_gethostbyname.c
+++ b/deps/cares/src/lib/ares_gethostbyname.c
@@ -25,14 +25,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#ifdef HAVE_STRINGS_H
#include <strings.h>
diff --git a/deps/cares/src/lib/ares_getnameinfo.c b/deps/cares/src/lib/ares_getnameinfo.c
index 53f91ca8459..966919ac232 100644
--- a/deps/cares/src/lib/ares_getnameinfo.c
+++ b/deps/cares/src/lib/ares_getnameinfo.c
@@ -31,14 +31,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#ifdef HAVE_NET_IF_H
#include <net/if.h>
diff --git a/deps/cares/src/lib/ares_init.c b/deps/cares/src/lib/ares_init.c
index 92187e463e6..0917dce2fe3 100644
--- a/deps/cares/src/lib/ares_init.c
+++ b/deps/cares/src/lib/ares_init.c
@@ -33,14 +33,7 @@
#include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+#include "ares_nameser.h"
#if defined(ANDROID) || defined(__ANDROID__)
#include <sys/system_properties.h>
@@ -1472,6 +1465,57 @@ static int init_by_resolv_conf(ares_channel channel)
/* Catch the case when all the above checks fail (which happens when there
is no network card or the cable is unplugged) */
status = ARES_EFILE;
+#elif defined(__MVS__)
+
+ struct __res_state *res = 0;
+ int count4, count6;
+ __STATEEXTIPV6 *v6;
+ struct server_state *pserver
+ if (0 == res) {
+ int rc = res_init();
+ while (rc == -1 && h_errno == TRY_AGAIN) {
+ rc = res_init();
+ }
+ if (rc == -1) {
+ return ARES_ENOMEM;
+ }
+ res = __res();
+ }
+
+ v6 = res->__res_extIPv6;
+ count4 = res->nscount;
+ if (v6) {
+ count6 = v6->__stat_nscount;
+ } else {
+ count6 = 0;
+ }
+
+ nservers = count4 + count6;
+ servers = ares_malloc(nservers * sizeof(struct server_state));
+ if (!servers)
+ return ARES_ENOMEM;
+
+ memset(servers, 0, nservers * sizeof(struct server_state));
+
+ pserver = servers;
+ for (int i = 0; i < count4; ++i, ++pserver) {
+ struct sockaddr_in *addr_in = &(res->nsaddr_list[i]);
+ pserver->addr.addrV4.s_addr = addr_in->sin_addr.s_addr;
+ pserver->addr.family = AF_INET;
+ pserver->addr.udp_port = addr_in->sin_port;
+ pserver->addr.tcp_port = addr_in->sin_port;
+ }
+
+ for (int j = 0; j < count6; ++j, ++pserver) {
+ struct sockaddr_in6 *addr_in = &(v6->__stat_nsaddr_list[j]);
+ memcpy(&(pserver->addr.addr.addr6), &(addr_in->sin6_addr),
+ sizeof(addr_in->sin6_addr));
+ pserver->addr.family = AF_INET6;
+ pserver->addr.udp_port = addr_in->sin6_port;
+ pserver->addr.tcp_port = addr_in->sin6_port;
+ }
+
+ status = ARES_EOF;
#elif defined(__riscos__)
@@ -1621,17 +1665,18 @@ static int init_by_resolv_conf(ares_channel channel)
int entries = 0;
while ((entries < MAXDNSRCH) && res.dnsrch[entries])
entries++;
-
- channel->domains = ares_malloc(entries * sizeof(char *));
- if (!channel->domains) {
- status = ARES_ENOMEM;
- } else {
- int i;
- channel->ndomains = entries;
- for (i = 0; i < channel->ndomains; ++i) {
- channel->domains[i] = ares_strdup(res.dnsrch[i]);
- if (!channel->domains[i])
- status = ARES_ENOMEM;
+ if(entries) {
+ channel->domains = ares_malloc(entries * sizeof(char *));
+ if (!channel->domains) {
+ status = ARES_ENOMEM;
+ } else {
+ int i;
+ channel->ndomains = entries;
+ for (i = 0; i < channel->ndomains; ++i) {
+ channel->domains[i] = ares_strdup(res.dnsrch[i]);
+ if (!channel->domains[i])
+ status = ARES_ENOMEM;
+ }
}
}
}
@@ -2470,9 +2515,10 @@ static void randomize_key(unsigned char* key,int key_data_len)
randomized = 1;
}
#else /* !WIN32 */
-#ifdef RANDOM_FILE
- FILE *f = fopen(RANDOM_FILE, "rb");
+#ifdef CARES_RANDOM_FILE
+ FILE *f = fopen(CARES_RANDOM_FILE, "rb");
if(f) {
+ setvbuf(f, NULL, _IONBF, 0);
counter = aresx_uztosi(fread(key, 1, key_data_len, f));
fclose(f);
}
diff --git a/deps/cares/src/lib/ares_library_init.c b/deps/cares/src/lib/ares_library_init.c
index 67563499bec..e0055d44a1c 100644
--- a/deps/cares/src/lib/ares_library_init.c
+++ b/deps/cares/src/lib/ares_library_init.c
@@ -40,13 +40,18 @@ static unsigned int ares_initialized;
static int ares_init_flags;
/* library-private global vars with visibility across the whole library */
+
+/* Some systems may return either NULL or a valid pointer on malloc(0). c-ares should
+ * never call malloc(0) so lets return NULL so we're more likely to find an issue if it
+ * were to occur. */
+
+static void *default_malloc(size_t size) { if (size == 0) { return NULL; } return malloc(size); }
+
#if defined(WIN32)
/* We need indirections to handle Windows DLL rules. */
-static void *default_malloc(size_t size) { return malloc(size); }
static void *default_realloc(void *p, size_t size) { return realloc(p, size); }
static void default_free(void *p) { free(p); }
#else
-# define default_malloc malloc
# define default_realloc realloc
# define default_free free
#endif
diff --git a/deps/cares/src/lib/ares_library_init.h b/deps/cares/src/lib/ares_library_init.h
index 2a2ba118b5f..b3896d9f7bb 100644
--- a/deps/cares/src/lib/ares_library_init.h
+++ b/deps/cares/src/lib/ares_library_init.h
@@ -23,7 +23,7 @@
#ifdef USE_WINSOCK
#include <iphlpapi.h>
-#include <ares_iphlpapi.h>
+#include "ares_iphlpapi.h"
typedef DWORD (WINAPI *fpGetNetworkParams_t) (FIXED_INFO*, DWORD*);
typedef BOOLEAN (APIENTRY *fpSystemFunction036_t) (void*, ULONG);
diff --git a/deps/cares/src/lib/ares_nameser.h b/deps/cares/src/lib/ares_nameser.h
new file mode 100644
index 00000000000..5270e5a3a6a
--- /dev/null
+++ b/deps/cares/src/lib/ares_nameser.h
@@ -0,0 +1,482 @@
+
+#ifndef ARES_NAMESER_H
+#define ARES_NAMESER_H
+
+#ifdef HAVE_ARPA_NAMESER_H
+# include <arpa/nameser.h>
+#endif
+#ifdef HAVE_ARPA_NAMESER_COMPAT_H
+# include <arpa/nameser_compat.h>
+#endif
+
+/* ============================================================================
+ * arpa/nameser.h may or may not provide ALL of the below defines, so check
+ * each one individually and set if not
+ * ============================================================================
+ */
+
+#ifndef NS_PACKETSZ
+# define NS_PACKETSZ 512 /* maximum packet size */
+#endif
+
+#ifndef NS_MAXDNAME
+# define NS_MAXDNAME 256 /* maximum domain name */
+#endif
+
+#ifndef NS_MAXCDNAME
+# define NS_MAXCDNAME 255 /* maximum compressed domain name */
+#endif
+
+#ifndef NS_MAXLABEL
+# define NS_MAXLABEL 63
+#endif
+
+#ifndef NS_HFIXEDSZ
+# define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */
+#endif
+
+#ifndef NS_QFIXEDSZ
+# define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */
+#endif
+
+#ifndef NS_RRFIXEDSZ
+# define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
+#endif
+
+#ifndef NS_INT16SZ
+# define NS_INT16SZ 2
+#endif
+
+#ifndef NS_INADDRSZ
+# define NS_INADDRSZ 4
+#endif
+
+#ifndef NS_IN6ADDRSZ
+# define NS_IN6ADDRSZ 16
+#endif
+
+#ifndef NS_CMPRSFLGS
+# define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */
+#endif
+
+#ifndef NS_DEFAULTPORT
+# define NS_DEFAULTPORT 53 /* For both TCP and UDP. */
+#endif
+
+/* ============================================================================
+ * arpa/nameser.h should provide these enumerations always, so if not found,
+ * provide them
+ * ============================================================================
+ */
+#ifndef HAVE_ARPA_NAMESER_H
+
+typedef enum __ns_class {
+ ns_c_invalid = 0, /* Cookie. */
+ ns_c_in = 1, /* Internet. */
+ ns_c_2 = 2, /* unallocated/unsupported. */
+ ns_c_chaos = 3, /* MIT Chaos-net. */
+ ns_c_hs = 4, /* MIT Hesiod. */
+ /* Query class values which do not appear in resource records */
+ ns_c_none = 254, /* for prereq. sections in update requests */
+ ns_c_any = 255, /* Wildcard match. */
+ ns_c_max = 65536
+} ns_class;
+
+typedef enum __ns_type {
+ ns_t_invalid = 0, /* Cookie. */
+ ns_t_a = 1, /* Host address. */
+ ns_t_ns = 2, /* Authoritative server. */
+ ns_t_md = 3, /* Mail destination. */
+ ns_t_mf = 4, /* Mail forwarder. */
+ ns_t_cname = 5, /* Canonical name. */
+ ns_t_soa = 6, /* Start of authority zone. */
+ ns_t_mb = 7, /* Mailbox domain name. */
+ ns_t_mg = 8, /* Mail group member. */
+ ns_t_mr = 9, /* Mail rename name. */
+ ns_t_null = 10, /* Null resource record. */
+ ns_t_wks = 11, /* Well known service. */
+ ns_t_ptr = 12, /* Domain name pointer. */
+ ns_t_hinfo = 13, /* Host information. */
+ ns_t_minfo = 14, /* Mailbox information. */
+ ns_t_mx = 15, /* Mail routing information. */
+ ns_t_txt = 16, /* Text strings. */
+ ns_t_rp = 17, /* Responsible person. */
+ ns_t_afsdb = 18, /* AFS cell database. */
+ ns_t_x25 = 19, /* X_25 calling address. */
+ ns_t_isdn = 20, /* ISDN calling address. */
+ ns_t_rt = 21, /* Router. */
+ ns_t_nsap = 22, /* NSAP address. */
+ ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */
+ ns_t_sig = 24, /* Security signature. */
+ ns_t_key = 25, /* Security key. */
+ ns_t_px = 26, /* X.400 mail mapping. */
+ ns_t_gpos = 27, /* Geographical position (withdrawn). */
+ ns_t_aaaa = 28, /* Ip6 Address. */
+ ns_t_loc = 29, /* Location Information. */
+ ns_t_nxt = 30, /* Next domain (security). */
+ ns_t_eid = 31, /* Endpoint identifier. */
+ ns_t_nimloc = 32, /* Nimrod Locator. */
+ ns_t_srv = 33, /* Server Selection. */
+ ns_t_atma = 34, /* ATM Address */
+ ns_t_naptr = 35, /* Naming Authority PoinTeR */
+ ns_t_kx = 36, /* Key Exchange */
+ ns_t_cert = 37, /* Certification record */
+ ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */
+ ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */
+ ns_t_sink = 40, /* Kitchen sink (experimentatl) */
+ ns_t_opt = 41, /* EDNS0 option (meta-RR) */
+ ns_t_apl = 42, /* Address prefix list (RFC3123) */
+ ns_t_ds = 43, /* Delegation Signer (RFC4034) */
+ ns_t_sshfp = 44, /* SSH Key Fingerprint (RFC4255) */
+ ns_t_rrsig = 46, /* Resource Record Signature (RFC4034) */
+ ns_t_nsec = 47, /* Next Secure (RFC4034) */
+ ns_t_dnskey = 48, /* DNS Public Key (RFC4034) */
+ ns_t_tkey = 249, /* Transaction key */
+ ns_t_tsig = 250, /* Transaction signature. */
+ ns_t_ixfr = 251, /* Incremental zone transfer. */
+ ns_t_axfr = 252, /* Transfer zone of authority. */
+ ns_t_mailb = 253, /* Transfer mailbox records. */
+ 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, /* Certification Authority Authorization. */
+ ns_t_max = 65536
+} ns_type;
+
+typedef enum __ns_opcode {
+ ns_o_query = 0, /* Standard query. */
+ ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */
+ ns_o_status = 2, /* Name server status query (unsupported). */
+ /* Opcode 3 is undefined/reserved. */
+ ns_o_notify = 4, /* Zone change notification. */
+ ns_o_update = 5, /* Zone update message. */
+ ns_o_max = 6
+} ns_opcode;
+
+typedef enum __ns_rcode {
+ ns_r_noerror = 0, /* No error occurred. */
+ ns_r_formerr = 1, /* Format error. */
+ ns_r_servfail = 2, /* Server failure. */
+ ns_r_nxdomain = 3, /* Name error. */
+ ns_r_notimpl = 4, /* Unimplemented. */
+ ns_r_refused = 5, /* Operation refused. */
+ /* these are for BIND_UPDATE */
+ ns_r_yxdomain = 6, /* Name exists */
+ ns_r_yxrrset = 7, /* RRset exists */
+ ns_r_nxrrset = 8, /* RRset does not exist */
+ ns_r_notauth = 9, /* Not authoritative for zone */
+ ns_r_notzone = 10, /* Zone of record different from zone section */
+ ns_r_max = 11,
+ /* The following are TSIG extended errors */
+ ns_r_badsig = 16,
+ ns_r_badkey = 17,
+ ns_r_badtime = 18
+} ns_rcode;
+
+#endif /* HAVE_ARPA_NAMESER_H */
+
+
+/* ============================================================================
+ * arpa/nameser_compat.h typically sets these. However on some systems
+ * arpa/nameser.h does, but may not set all of them. Lets conditionally
+ * define each
+ * ============================================================================
+ */
+
+#ifndef PACKETSZ
+# define PACKETSZ NS_PACKETSZ
+#endif
+
+#ifndef MAXDNAME
+# define MAXDNAME NS_MAXDNAME
+#endif
+
+#ifndef MAXCDNAME
+# define MAXCDNAME NS_MAXCDNAME
+#endif
+
+#ifndef MAXLABEL
+# define MAXLABEL NS_MAXLABEL
+#endif
+
+#ifndef HFIXEDSZ
+# define HFIXEDSZ NS_HFIXEDSZ
+#endif
+
+#ifndef QFIXEDSZ
+# define QFIXEDSZ NS_QFIXEDSZ
+#endif
+
+#ifndef RRFIXEDSZ
+# define RRFIXEDSZ NS_RRFIXEDSZ
+#endif
+
+#ifndef INDIR_MASK
+# define INDIR_MASK NS_CMPRSFLGS
+#endif
+
+#ifndef NAMESERVER_PORT
+# define NAMESERVER_PORT NS_DEFAULTPORT
+#endif
+
+
+/* opcodes */
+#ifndef O_QUERY
+# define O_QUERY 0 /* ns_o_query */
+#endif
+#ifndef O_IQUERY
+# define O_IQUERY 1 /* ns_o_iquery */
+#endif
+#ifndef O_STATUS
+# define O_STATUS 2 /* ns_o_status */
+#endif
+#ifndef O_NOTIFY
+# define O_NOTIFY 4 /* ns_o_notify */
+#endif
+#ifndef O_UPDATE
+# define O_UPDATE 5 /* ns_o_update */
+#endif
+
+
+/* response codes */
+#ifndef SERVFAIL
+# define SERVFAIL ns_r_servfail
+#endif
+#ifndef NOTIMP
+# define NOTIMP ns_r_notimpl
+#endif
+#ifndef REFUSED
+# define REFUSED ns_r_refused
+#endif
+#if defined(_WIN32) && !defined(HAVE_ARPA_NAMESER_COMPAT_H) && defined(NOERROR)
+# undef NOERROR /* it seems this is already defined in winerror.h */
+#endif
+#ifndef NOERROR
+# define NOERROR ns_r_noerror
+#endif
+#ifndef FORMERR
+# define FORMERR ns_r_formerr
+#endif
+#ifndef NXDOMAIN
+# define NXDOMAIN ns_r_nxdomain
+#endif
+/* Non-standard response codes, use numeric values */
+#ifndef YXDOMAIN
+# define YXDOMAIN 6 /* ns_r_yxdomain */
+#endif
+#ifndef YXRRSET
+# define YXRRSET 7 /* ns_r_yxrrset */
+#endif
+#ifndef NXRRSET
+# define NXRRSET 8 /* ns_r_nxrrset */
+#endif
+#ifndef NOTAUTH
+# define NOTAUTH 9 /* ns_r_notauth */
+#endif
+#ifndef NOTZONE
+# define NOTZONE 10 /* ns_r_notzone */
+#endif
+#ifndef TSIG_BADSIG
+# define TSIG_BADSIG 16 /* ns_r_badsig */
+#endif
+#ifndef TSIG_BADKEY
+# define TSIG_BADKEY 17 /* ns_r_badkey */
+#endif
+#ifndef TSIG_BADTIME
+# define TSIG_BADTIME 18 /* ns_r_badtime */
+#endif
+
+
+/* classes */
+#ifndef C_IN
+# define C_IN 1 /* ns_c_in */
+#endif
+#ifndef C_CHAOS
+# define C_CHAOS 3 /* ns_c_chaos */
+#endif
+#ifndef C_HS
+# define C_HS 4 /* ns_c_hs */
+#endif
+#ifndef C_NONE
+# define C_NONE 254 /* ns_c_none */
+#endif
+#ifndef C_ANY
+# define C_ANY 255 /* ns_c_any */
+#endif
+
+
+/* types */
+#ifndef T_A
+# define T_A 1 /* ns_t_a */
+#endif
+#ifndef T_NS
+# define T_NS 2 /* ns_t_ns */
+#endif
+#ifndef T_MD
+# define T_MD 3 /* ns_t_md */
+#endif
+#ifndef T_MF
+# define T_MF 4 /* ns_t_mf */
+#endif
+#ifndef T_CNAME
+# define T_CNAME 5 /* ns_t_cname */
+#endif
+#ifndef T_SOA
+# define T_SOA 6 /* ns_t_soa */
+#endif
+#ifndef T_MB
+# define T_MB 7 /* ns_t_mb */
+#endif
+#ifndef T_MG
+# define T_MG 8 /* ns_t_mg */
+#endif
+#ifndef T_MR
+# define T_MR 9 /* ns_t_mr */
+#endif
+#ifndef T_NULL
+# define T_NULL 10 /* ns_t_null */
+#endif
+#ifndef T_WKS
+# define T_WKS 11 /* ns_t_wks */
+#endif
+#ifndef T_PTR
+# define T_PTR 12 /* ns_t_ptr */
+#endif
+#ifndef T_HINFO
+# define T_HINFO 13 /* ns_t_hinfo */
+#endif
+#ifndef T_MINFO
+# define T_MINFO 14 /* ns_t_minfo */
+#endif
+#ifndef T_MX
+# define T_MX 15 /* ns_t_mx */
+#endif
+#ifndef T_TXT
+# define T_TXT 16 /* ns_t_txt */
+#endif
+#ifndef T_RP
+# define T_RP 17 /* ns_t_rp */
+#endif
+#ifndef T_AFSDB
+# define T_AFSDB 18 /* ns_t_afsdb */
+#endif
+#ifndef T_X25
+# define T_X25 19 /* ns_t_x25 */
+#endif
+#ifndef T_ISDN
+# define T_ISDN 20 /* ns_t_isdn */
+#endif
+#ifndef T_RT
+# define T_RT 21 /* ns_t_rt */
+#endif
+#ifndef T_NSAP
+# define T_NSAP 22 /* ns_t_nsap */
+#endif
+#ifndef T_NSAP_PTR
+# define T_NSAP_PTR 23 /* ns_t_nsap_ptr */
+#endif
+#ifndef T_SIG
+# define T_SIG 24 /* ns_t_sig */
+#endif
+#ifndef T_KEY
+# define T_KEY 25 /* ns_t_key */
+#endif
+#ifndef T_PX
+# define T_PX 26 /* ns_t_px */
+#endif
+#ifndef T_GPOS
+# define T_GPOS 27 /* ns_t_gpos */
+#endif
+#ifndef T_AAAA
+# define T_AAAA 28 /* ns_t_aaaa */
+#endif
+#ifndef T_LOC
+# define T_LOC 29 /* ns_t_loc */
+#endif
+#ifndef T_NXT
+# define T_NXT 30 /* ns_t_nxt */
+#endif
+#ifndef T_EID
+# define T_EID 31 /* ns_t_eid */
+#endif
+#ifndef T_NIMLOC
+# define T_NIMLOC 32 /* ns_t_nimloc */
+#endif
+#ifndef T_SRV
+# define T_SRV 33 /* ns_t_srv */
+#endif
+#ifndef T_ATMA
+# define T_ATMA 34 /* ns_t_atma */
+#endif
+#ifndef T_NAPTR
+# define T_NAPTR 35 /* ns_t_naptr */
+#endif
+#ifndef T_KX
+# define T_KX 36 /* ns_t_kx */
+#endif
+#ifndef T_CERT
+# define T_CERT 37 /* ns_t_cert */
+#endif
+#ifndef T_A6
+# define T_A6 38 /* ns_t_a6 */
+#endif
+#ifndef T_DNAME
+# define T_DNAME 39 /* ns_t_dname */
+#endif
+#ifndef T_SINK
+# define T_SINK 40 /* ns_t_sink */
+#endif
+#ifndef T_OPT
+# define T_OPT 41 /* ns_t_opt */
+#endif
+#ifndef T_APL
+# define T_APL 42 /* ns_t_apl */
+#endif
+#ifndef T_DS
+# define T_DS 43 /* ns_t_ds */
+#endif
+#ifndef T_SSHFP
+# define T_SSHFP 44 /* ns_t_sshfp */
+#endif
+#ifndef T_RRSIG
+# define T_RRSIG 46 /* ns_t_rrsig */
+#endif
+#ifndef T_NSEC
+# define T_NSEC 47 /* ns_t_nsec */
+#endif
+#ifndef T_DNSKEY
+# define T_DNSKEY 48 /* ns_t_dnskey */
+#endif
+#ifndef T_TKEY
+# define T_TKEY 249 /* ns_t_tkey */
+#endif
+#ifndef T_TSIG
+# define T_TSIG 250 /* ns_t_tsig */
+#endif
+#ifndef T_IXFR
+# define T_IXFR 251 /* ns_t_ixfr */
+#endif
+#ifndef T_AXFR
+# define T_AXFR 252 /* ns_t_axfr */
+#endif
+#ifndef T_MAILB
+# define T_MAILB 253 /* ns_t_mailb */
+#endif
+#ifndef T_MAILA
+# define T_MAILA 254 /* ns_t_maila */
+#endif
+#ifndef T_ANY
+# define T_ANY 255 /* ns_t_any */
+#endif
+#ifndef T_ZXFR
+# define T_ZXFR 256 /* ns_t_zxfr */
+#endif
+#ifndef T_CAA
+# define T_CAA 257 /* ns_t_caa */
+#endif
+#ifndef T_MAX
+# define T_MAX 65536 /* ns_t_max */
+#endif
+
+
+#endif /* ARES_NAMESER_H */
diff --git a/deps/cares/src/lib/ares_parse_a_reply.c b/deps/cares/src/lib/ares_parse_a_reply.c
index e71c993f8de..b08ac8760ff 100644
--- a/deps/cares/src/lib/ares_parse_a_reply.c
+++ b/deps/cares/src/lib/ares_parse_a_reply.c
@@ -26,14 +26,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#ifdef HAVE_STRINGS_H
# include <strings.h>
@@ -113,7 +107,7 @@ int ares_parse_a_reply(const unsigned char *abuf, int alen,
while (next_cname)
{
if(next_cname->alias)
- aliases[alias++] = strdup(next_cname->alias);
+ aliases[alias++] = ares_strdup(next_cname->alias);
if(next_cname->ttl < cname_ttl)
cname_ttl = next_cname->ttl;
next_cname = next_cname->next;
@@ -135,7 +129,7 @@ int ares_parse_a_reply(const unsigned char *abuf, int alen,
if (ai.cnames)
{
- hostent->h_name = strdup(ai.cnames->name);
+ hostent->h_name = ares_strdup(ai.cnames->name);
ares_free(question_hostname);
}
else
diff --git a/deps/cares/src/lib/ares_parse_aaaa_reply.c b/deps/cares/src/lib/ares_parse_aaaa_reply.c
index 346d430750b..6f4744a8dc4 100644
--- a/deps/cares/src/lib/ares_parse_aaaa_reply.c
+++ b/deps/cares/src/lib/ares_parse_aaaa_reply.c
@@ -27,14 +27,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#ifdef HAVE_STRINGS_H
# include <strings.h>
@@ -115,7 +109,7 @@ int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
while (next_cname)
{
if(next_cname->alias)
- aliases[alias++] = strdup(next_cname->alias);
+ aliases[alias++] = ares_strdup(next_cname->alias);
if(next_cname->ttl < cname_ttl)
cname_ttl = next_cname->ttl;
next_cname = next_cname->next;
@@ -137,7 +131,7 @@ int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
if (ai.cnames)
{
- hostent->h_name = strdup(ai.cnames->name);
+ hostent->h_name = ares_strdup(ai.cnames->name);
ares_free(question_hostname);
}
else
diff --git a/deps/cares/src/lib/ares_parse_caa_reply.c b/deps/cares/src/lib/ares_parse_caa_reply.c
index 620f444e007..f6d4d3c61f4 100644
--- a/deps/cares/src/lib/ares_parse_caa_reply.c
+++ b/deps/cares/src/lib/ares_parse_caa_reply.c
@@ -25,14 +25,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#ifdef HAVE_STRINGS_H
# include <strings.h>
@@ -43,10 +37,6 @@
#include "ares_data.h"
#include "ares_private.h"
-#ifndef T_CAA
-# define T_CAA 257 /* Certification Authority Authorization */
-#endif
-
int
ares_parse_caa_reply (const unsigned char *abuf, int alen,
struct ares_caa_reply **caa_out)
diff --git a/deps/cares/src/lib/ares_parse_mx_reply.c b/deps/cares/src/lib/ares_parse_mx_reply.c
index e6336473e0a..a497f558738 100644
--- a/deps/cares/src/lib/ares_parse_mx_reply.c
+++ b/deps/cares/src/lib/ares_parse_mx_reply.c
@@ -26,14 +26,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#include "ares.h"
#include "ares_dns.h"
diff --git a/deps/cares/src/lib/ares_parse_naptr_reply.c b/deps/cares/src/lib/ares_parse_naptr_reply.c
index a14c226a9e7..dd984c0fea8 100644
--- a/deps/cares/src/lib/ares_parse_naptr_reply.c
+++ b/deps/cares/src/lib/ares_parse_naptr_reply.c
@@ -26,25 +26,14 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#include "ares.h"
#include "ares_dns.h"
#include "ares_data.h"
#include "ares_private.h"
-/* AIX portability check */
-#ifndef T_NAPTR
- #define T_NAPTR 35 /* naming authority pointer */
-#endif
-
int
ares_parse_naptr_reply (const unsigned char *abuf, int alen,
struct ares_naptr_reply **naptr_out)
diff --git a/deps/cares/src/lib/ares_parse_ns_reply.c b/deps/cares/src/lib/ares_parse_ns_reply.c
index 7bb51429db0..47d12994c96 100644
--- a/deps/cares/src/lib/ares_parse_ns_reply.c
+++ b/deps/cares/src/lib/ares_parse_ns_reply.c
@@ -29,14 +29,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#include "ares.h"
#include "ares_dns.h"
@@ -68,7 +62,7 @@ int ares_parse_ns_reply( const unsigned char* abuf, int alen,
/* Expand the name from the question, and skip past the question. */
aptr = abuf + HFIXEDSZ;
- status = ares__expand_name_for_response( aptr, abuf, alen, &hostname, &len);
+ status = ares__expand_name_for_response( aptr, abuf, alen, &hostname, &len, 0);
if ( status != ARES_SUCCESS )
return status;
if ( aptr + len + QFIXEDSZ > abuf + alen )
@@ -91,7 +85,7 @@ int ares_parse_ns_reply( const unsigned char* abuf, int alen,
for ( i = 0; i < ( int ) ancount; i++ )
{
/* Decode the RR up to the data field. */
- status = ares__expand_name_for_response( aptr, abuf, alen, &rr_name, &len );
+ status = ares__expand_name_for_response( aptr, abuf, alen, &rr_name, &len, 0);
if ( status != ARES_SUCCESS )
break;
aptr += len;
@@ -116,7 +110,7 @@ int ares_parse_ns_reply( const unsigned char* abuf, int alen,
{
/* Decode the RR data and add it to the nameservers list */
status = ares__expand_name_for_response( aptr, abuf, alen, &rr_data,
- &len);
+ &len, 1);
if ( status != ARES_SUCCESS )
{
ares_free(rr_name);
diff --git a/deps/cares/src/lib/ares_parse_ptr_reply.c b/deps/cares/src/lib/ares_parse_ptr_reply.c
index 29e22cb17b6..ae78edf1951 100644
--- a/deps/cares/src/lib/ares_parse_ptr_reply.c
+++ b/deps/cares/src/lib/ares_parse_ptr_reply.c
@@ -22,14 +22,8 @@
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#ifdef HAVE_STRINGS_H
# include <strings.h>
@@ -48,7 +42,7 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
long len;
const unsigned char *aptr;
char *ptrname, *hostname, *rr_name, *rr_data;
- struct hostent *hostent;
+ struct hostent *hostent = NULL;
int aliascnt = 0;
int alias_alloc = 8;
char ** aliases;
@@ -69,7 +63,7 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
/* Expand the name from the question, and skip past the question. */
aptr = abuf + HFIXEDSZ;
- status = ares__expand_name_for_response(aptr, abuf, alen, &ptrname, &len);
+ status = ares__expand_name_for_response(aptr, abuf, alen, &ptrname, &len, 0);
if (status != ARES_SUCCESS)
return status;
if (aptr + len + QFIXEDSZ > abuf + alen)
@@ -90,7 +84,7 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
for (i = 0; i < (int)ancount; i++)
{
/* Decode the RR up to the data field. */
- status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len);
+ status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len, 0);
if (status != ARES_SUCCESS)
break;
aptr += len;
@@ -116,7 +110,7 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
{
/* Decode the RR data and set hostname to it. */
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data,
- &len);
+ &len, 1);
if (status != ARES_SUCCESS)
{
ares_free(rr_name);
@@ -152,7 +146,7 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
{
/* Decode the RR data and replace ptrname with it. */
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data,
- &len);
+ &len, 1);
if (status != ARES_SUCCESS)
{
ares_free(rr_name);
@@ -175,41 +169,54 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
status = ARES_ENODATA;
if (status == ARES_SUCCESS)
{
- /* We got our answer. Allocate memory to build the host entry. */
- hostent = ares_malloc(sizeof(struct hostent));
- if (hostent)
- {
- hostent->h_addr_list = ares_malloc(2 * sizeof(char *));
- if (hostent->h_addr_list)
- {
- hostent->h_addr_list[0] = ares_malloc(addrlen);
- if (hostent->h_addr_list[0])
- {
- hostent->h_aliases = ares_malloc((aliascnt+1) * sizeof (char *));
- if (hostent->h_aliases)
- {
- /* Fill in the hostent and return successfully. */
- hostent->h_name = hostname;
- for (i=0 ; i<aliascnt ; i++)
- hostent->h_aliases[i] = aliases[i];
- hostent->h_aliases[aliascnt] = NULL;
- hostent->h_addrtype = aresx_sitoss(family);
- hostent->h_length = aresx_sitoss(addrlen);
- memcpy(hostent->h_addr_list[0], addr, addrlen);
- hostent->h_addr_list[1] = NULL;
- *host = hostent;
- ares_free(aliases);
- ares_free(ptrname);
- return ARES_SUCCESS;
- }
- ares_free(hostent->h_addr_list[0]);
- }
- ares_free(hostent->h_addr_list);
- }
- ares_free(hostent);
- }
+ /* If we don't reach the end, we must have failed due to out of memory */
status = ARES_ENOMEM;
+
+ /* We got our answer. Allocate memory to build the host entry. */
+ hostent = ares_malloc(sizeof(*hostent));
+ if (!hostent)
+ goto fail;
+
+ /* If we don't memset here, cleanups may fail */
+ memset(hostent, 0, sizeof(*hostent));
+
+ hostent->h_addr_list = ares_malloc(2 * sizeof(char *));
+ if (!hostent->h_addr_list)
+ goto fail;
+
+
+ if (addr && addrlen) {
+ hostent->h_addr_list[0] = ares_malloc(addrlen);
+ if (!hostent->h_addr_list[0])
+ goto fail;
+ } else {
+ hostent->h_addr_list[0] = NULL;
+ }
+
+ hostent->h_aliases = ares_malloc((aliascnt+1) * sizeof (char *));
+ if (!hostent->h_aliases)
+ goto fail;
+
+ /* Fill in the hostent and return successfully. */
+ hostent->h_name = hostname;
+ for (i=0 ; i<aliascnt ; i++)
+ hostent->h_aliases[i] = aliases[i];
+ hostent->h_aliases[aliascnt] = NULL;
+ hostent->h_addrtype = aresx_sitoss(family);
+ hostent->h_length = aresx_sitoss(addrlen);
+ if (addr && addrlen)
+ memcpy(hostent->h_addr_list[0], addr, addrlen);
+ hostent->h_addr_list[1] = NULL;
+ *host = hostent;
+ ares_free(aliases);
+ ares_free(ptrname);
+
+ return ARES_SUCCESS;
}
+
+fail:
+ ares_free_hostent(hostent);
+
for (i=0 ; i<aliascnt ; i++)
if (aliases[i])
ares_free(aliases[i]);
diff --git a/deps/cares/src/lib/ares_parse_soa_reply.c b/deps/cares/src/lib/ares_parse_soa_reply.c
index 7cfaed2b333..3935eec9db4 100644
--- a/deps/cares/src/lib/ares_parse_soa_reply.c
+++ b/deps/cares/src/lib/ares_parse_soa_reply.c
@@ -26,14 +26,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#include "ares.h"
#include "ares_dns.h"
@@ -62,11 +56,11 @@ 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);
+ status = ares__expand_name_for_response(aptr, abuf, alen, &qname, &len, 0);
if (status != ARES_SUCCESS)
goto failed_stat;
@@ -89,7 +83,7 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
for (i = 0; i < ancount; i++)
{
rr_name = NULL;
- status = ares__expand_name_for_response (aptr, abuf, alen, &rr_name, &len);
+ status = ares__expand_name_for_response (aptr, abuf, alen, &rr_name, &len, 0);
if (status != ARES_SUCCESS)
{
ares_free(rr_name);
@@ -126,7 +120,7 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
/* nsname */
status = ares__expand_name_for_response(aptr, abuf, alen, &soa->nsname,
- &len);
+ &len, 0);
if (status != ARES_SUCCESS)
{
ares_free(rr_name);
@@ -136,7 +130,7 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
/* hostmaster */
status = ares__expand_name_for_response(aptr, abuf, alen,
- &soa->hostmaster, &len);
+ &soa->hostmaster, &len, 0);
if (status != ARES_SUCCESS)
{
ares_free(rr_name);
@@ -164,9 +158,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;
}
diff --git a/deps/cares/src/lib/ares_parse_srv_reply.c b/deps/cares/src/lib/ares_parse_srv_reply.c
index 824ff3aedf0..0d8f4d2098b 100644
--- a/deps/cares/src/lib/ares_parse_srv_reply.c
+++ b/deps/cares/src/lib/ares_parse_srv_reply.c
@@ -26,25 +26,14 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#include "ares.h"
#include "ares_dns.h"
#include "ares_data.h"
#include "ares_private.h"
-/* AIX portability check */
-#ifndef T_SRV
-# define T_SRV 33 /* server selection */
-#endif
-
int
ares_parse_srv_reply (const unsigned char *abuf, int alen,
struct ares_srv_reply **srv_out)
diff --git a/deps/cares/src/lib/ares_parse_txt_reply.c b/deps/cares/src/lib/ares_parse_txt_reply.c
index 3f47e23f086..6848a092bbc 100644
--- a/deps/cares/src/lib/ares_parse_txt_reply.c
+++ b/deps/cares/src/lib/ares_parse_txt_reply.c
@@ -26,14 +26,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#ifdef HAVE_STRINGS_H
# include <strings.h>
diff --git a/deps/cares/src/lib/ares_private.h b/deps/cares/src/lib/ares_private.h
index 50b2ba06e15..09f65062f02 100644
--- a/deps/cares/src/lib/ares_private.h
+++ b/deps/cares/src/lib/ares_private.h
@@ -356,9 +356,13 @@ int ares__read_line(FILE *fp, char **buf, size_t *bufsize);
void ares__free_query(struct query *query);
unsigned short ares__generate_new_id(rc4_key* key);
struct timeval ares__tvnow(void);
+int ares__expand_name_validated(const unsigned char *encoded,
+ const unsigned char *abuf,
+ int alen, char **s, long *enclen,
+ int is_hostname);
int ares__expand_name_for_response(const unsigned char *encoded,
const unsigned char *abuf, int alen,
- char **s, long *enclen);
+ char **s, long *enclen, int is_hostname);
void ares__init_servers_state(ares_channel channel);
void ares__destroy_servers_state(ares_channel channel);
int ares__parse_qtype_reply(const unsigned char* abuf, int alen, int* qtype);
diff --git a/deps/cares/src/lib/ares_process.c b/deps/cares/src/lib/ares_process.c
index 65c1b7ff1a8..87329e35886 100644
--- a/deps/cares/src/lib/ares_process.c
+++ b/deps/cares/src/lib/ares_process.c
@@ -32,14 +32,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
-#include "nameser.h"
+#include "ares_nameser.h"
#ifdef HAVE_STRINGS_H
# include <strings.h>
@@ -611,8 +605,7 @@ static void process_answer(ares_channel channel, unsigned char *abuf,
packetsz = PACKETSZ;
/* If we use EDNS and server answers with FORMERR without an OPT RR, the protocol
* extension is not understood by the responder. We must retry the query
- * without EDNS enabled.
- */
+ * without EDNS enabled. */
if (channel->flags & ARES_FLAG_EDNS)
{
packetsz = channel->ednspsz;
diff --git a/deps/cares/src/lib/ares_query.c b/deps/cares/src/lib/ares_query.c
index 5bbb2f5c326..508274db36c 100644
--- a/deps/cares/src/lib/ares_query.c
+++ b/deps/cares/src/lib/ares_query.c
@@ -19,14 +19,8 @@
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#include "ares.h"
#include "ares_dns.h"
diff --git a/deps/cares/src/lib/ares_send.c b/deps/cares/src/lib/ares_send.c
index f4f1f951197..75ba9e4cc60 100644
--- a/deps/cares/src/lib/ares_send.c
+++ b/deps/cares/src/lib/ares_send.c
@@ -19,14 +19,8 @@
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#include "ares.h"
#include "ares_dns.h"
diff --git a/deps/cares/src/lib/ares_setup.h b/deps/cares/src/lib/ares_setup.h
index 4df796116a0..6ad2cee6a8c 100644
--- a/deps/cares/src/lib/ares_setup.h
+++ b/deps/cares/src/lib/ares_setup.h
@@ -178,8 +178,11 @@
/*
* Android does have the arpa/nameser.h header which is detected by configure
* but it appears to be empty with recent NDK r7b / r7c, so we undefine here.
+ * z/OS does have the arpa/nameser.h header which is detected by configure
+ * but it is not fully implemented and missing identifiers, so udefine here.
*/
-#if (defined(ANDROID) || defined(__ANDROID__)) && defined(HAVE_ARPA_NAMESER_H)
+#if (defined(ANDROID) || defined(__ANDROID__) || defined(__MVS__)) && \
+ defined(HAVE_ARPA_NAMESER_H)
# undef HAVE_ARPA_NAMESER_H
#endif
diff --git a/deps/cares/src/lib/ares_strsplit.c b/deps/cares/src/lib/ares_strsplit.c
index b57a30f2a99..97b4e5d5bbb 100644
--- a/deps/cares/src/lib/ares_strsplit.c
+++ b/deps/cares/src/lib/ares_strsplit.c
@@ -13,6 +13,10 @@
* without express or implied warranty.
*/
+#if defined(__MVS__)
+#include <strings.h>
+#endif
+
#include "ares_setup.h"
#include "ares_strsplit.h"
#include "ares.h"
diff --git a/deps/cares/src/lib/inet_net_pton.c b/deps/cares/src/lib/inet_net_pton.c
index af1a534a05a..840de506529 100644
--- a/deps/cares/src/lib/inet_net_pton.c
+++ b/deps/cares/src/lib/inet_net_pton.c
@@ -24,14 +24,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#include "ares.h"
#include "ares_ipv6.h"
diff --git a/deps/cares/src/lib/inet_ntop.c b/deps/cares/src/lib/inet_ntop.c
index 1935a871ced..6645c0a4679 100644
--- a/deps/cares/src/lib/inet_ntop.c
+++ b/deps/cares/src/lib/inet_ntop.c
@@ -23,14 +23,8 @@
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
-#ifdef HAVE_ARPA_NAMESER_H
-# include <arpa/nameser.h>
-#else
-# include "nameser.h"
-#endif
-#ifdef HAVE_ARPA_NAMESER_COMPAT_H
-# include <arpa/nameser_compat.h>
-#endif
+
+#include "ares_nameser.h"
#include "ares.h"
#include "ares_ipv6.h"
diff --git a/deps/cares/src/lib/nameser.h b/deps/cares/src/lib/nameser.h
deleted file mode 100644
index 5c1acce2155..00000000000
--- a/deps/cares/src/lib/nameser.h
+++ /dev/null
@@ -1,218 +0,0 @@
-
-#ifndef ARES_NAMESER_H
-#define ARES_NAMESER_H
-
-/* header file provided by liren@vivisimo.com */
-
-#ifndef HAVE_ARPA_NAMESER_H
-
-#define NS_PACKETSZ 512 /* maximum packet size */
-#define NS_MAXDNAME 256 /* maximum domain name */
-#define NS_MAXCDNAME 255 /* maximum compressed domain name */
-#define NS_MAXLABEL 63
-#define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */
-#define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */
-#define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
-#define NS_INT16SZ 2
-#define NS_INADDRSZ 4
-#define NS_IN6ADDRSZ 16
-#define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */
-#define NS_DEFAULTPORT 53 /* For both TCP and UDP. */
-
-typedef enum __ns_class {
- ns_c_invalid = 0, /* Cookie. */
- ns_c_in = 1, /* Internet. */
- ns_c_2 = 2, /* unallocated/unsupported. */
- ns_c_chaos = 3, /* MIT Chaos-net. */
- ns_c_hs = 4, /* MIT Hesiod. */
- /* Query class values which do not appear in resource records */
- ns_c_none = 254, /* for prereq. sections in update requests */
- ns_c_any = 255, /* Wildcard match. */
- ns_c_max = 65536
-} ns_class;
-
-typedef enum __ns_type {
- ns_t_invalid = 0, /* Cookie. */
- ns_t_a = 1, /* Host address. */
- ns_t_ns = 2, /* Authoritative server. */
- ns_t_md = 3, /* Mail destination. */
- ns_t_mf = 4, /* Mail forwarder. */
- ns_t_cname = 5, /* Canonical name. */
- ns_t_soa = 6, /* Start of authority zone. */
- ns_t_mb = 7, /* Mailbox domain name. */
- ns_t_mg = 8, /* Mail group member. */
- ns_t_mr = 9, /* Mail rename name. */
- ns_t_null = 10, /* Null resource record. */
- ns_t_wks = 11, /* Well known service. */
- ns_t_ptr = 12, /* Domain name pointer. */
- ns_t_hinfo = 13, /* Host information. */
- ns_t_minfo = 14, /* Mailbox information. */
- ns_t_mx = 15, /* Mail routing information. */
- ns_t_txt = 16, /* Text strings. */
- ns_t_rp = 17, /* Responsible person. */
- ns_t_afsdb = 18, /* AFS cell database. */
- ns_t_x25 = 19, /* X_25 calling address. */
- ns_t_isdn = 20, /* ISDN calling address. */
- ns_t_rt = 21, /* Router. */
- ns_t_nsap = 22, /* NSAP address. */
- ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */
- ns_t_sig = 24, /* Security signature. */
- ns_t_key = 25, /* Security key. */
- ns_t_px = 26, /* X.400 mail mapping. */
- ns_t_gpos = 27, /* Geographical position (withdrawn). */
- ns_t_aaaa = 28, /* Ip6 Address. */
- ns_t_loc = 29, /* Location Information. */
- ns_t_nxt = 30, /* Next domain (security). */
- ns_t_eid = 31, /* Endpoint identifier. */
- ns_t_nimloc = 32, /* Nimrod Locator. */
- ns_t_srv = 33, /* Server Selection. */
- ns_t_atma = 34, /* ATM Address */
- ns_t_naptr = 35, /* Naming Authority PoinTeR */
- ns_t_kx = 36, /* Key Exchange */
- ns_t_cert = 37, /* Certification record */
- ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */
- ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */
- ns_t_sink = 40, /* Kitchen sink (experimentatl) */
- ns_t_opt = 41, /* EDNS0 option (meta-RR) */
- ns_t_apl = 42, /* Address prefix list (RFC3123) */
- ns_t_ds = 43, /* Delegation Signer (RFC4034) */
- ns_t_sshfp = 44, /* SSH Key Fingerprint (RFC4255) */
- ns_t_rrsig = 46, /* Resource Record Signature (RFC4034) */
- ns_t_nsec = 47, /* Next Secure (RFC4034) */
- ns_t_dnskey = 48, /* DNS Public Key (RFC4034) */
- ns_t_tkey = 249, /* Transaction key */
- ns_t_tsig = 250, /* Transaction signature. */
- ns_t_ixfr = 251, /* Incremental zone transfer. */
- ns_t_axfr = 252, /* Transfer zone of authority. */
- ns_t_mailb = 253, /* Transfer mailbox records. */
- 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, /* Certification Authority Authorization. */
- ns_t_max = 65536
-} ns_type;
-
-typedef enum __ns_opcode {
- ns_o_query = 0, /* Standard query. */
- ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */
- ns_o_status = 2, /* Name server status query (unsupported). */
- /* Opcode 3 is undefined/reserved. */
- ns_o_notify = 4, /* Zone change notification. */
- ns_o_update = 5, /* Zone update message. */
- ns_o_max = 6
-} ns_opcode;
-
-typedef enum __ns_rcode {
- ns_r_noerror = 0, /* No error occurred. */
- ns_r_formerr = 1, /* Format error. */
- ns_r_servfail = 2, /* Server failure. */
- ns_r_nxdomain = 3, /* Name error. */
- ns_r_notimpl = 4, /* Unimplemented. */
- ns_r_refused = 5, /* Operation refused. */
- /* these are for BIND_UPDATE */
- ns_r_yxdomain = 6, /* Name exists */
- ns_r_yxrrset = 7, /* RRset exists */
- ns_r_nxrrset = 8, /* RRset does not exist */
- ns_r_notauth = 9, /* Not authoritative for zone */
- ns_r_notzone = 10, /* Zone of record different from zone section */
- ns_r_max = 11,
- /* The following are TSIG extended errors */
- ns_r_badsig = 16,
- ns_r_badkey = 17,
- ns_r_badtime = 18
-} ns_rcode;
-
-#endif /* HAVE_ARPA_NAMESER_H */
-
-#ifndef HAVE_ARPA_NAMESER_COMPAT_H
-
-#define PACKETSZ NS_PACKETSZ
-#define MAXDNAME NS_MAXDNAME
-#define MAXCDNAME NS_MAXCDNAME
-#define MAXLABEL NS_MAXLABEL
-#define HFIXEDSZ NS_HFIXEDSZ
-#define QFIXEDSZ NS_QFIXEDSZ
-#define RRFIXEDSZ NS_RRFIXEDSZ
-#define INDIR_MASK NS_CMPRSFLGS
-#define NAMESERVER_PORT NS_DEFAULTPORT
-
-#define QUERY ns_o_query
-
-#define SERVFAIL ns_r_servfail
-#define NOTIMP ns_r_notimpl
-#define REFUSED ns_r_refused
-#undef NOERROR /* it seems this is already defined in winerror.h */
-#define NOERROR ns_r_noerror
-#define FORMERR ns_r_formerr
-#define NXDOMAIN ns_r_nxdomain
-
-#define C_IN ns_c_in
-#define C_CHAOS ns_c_chaos
-#define C_HS ns_c_hs
-#define C_NONE ns_c_none
-#define C_ANY ns_c_any
-
-#define T_A ns_t_a
-#define T_NS ns_t_ns
-#define T_MD ns_t_md
-#define T_MF ns_t_mf
-#define T_CNAME ns_t_cname
-#define T_SOA ns_t_soa
-#define T_MB ns_t_mb
-#define T_MG ns_t_mg
-#define T_MR ns_t_mr
-#define T_NULL ns_t_null
-#define T_WKS ns_t_wks
-#define T_PTR ns_t_ptr
-#define T_HINFO ns_t_hinfo
-#define T_MINFO ns_t_minfo
-#define T_MX ns_t_mx
-#define T_TXT ns_t_txt
-#define T_RP ns_t_rp
-#define T_AFSDB ns_t_afsdb
-#define T_X25 ns_t_x25
-#define T_ISDN ns_t_isdn
-#define T_RT ns_t_rt
-#define T_NSAP ns_t_nsap
-#define T_NSAP_PTR ns_t_nsap_ptr
-#define T_SIG ns_t_sig
-#define T_KEY ns_t_key
-#define T_PX ns_t_px
-#define T_GPOS ns_t_gpos
-#define T_AAAA ns_t_aaaa
-#define T_LOC ns_t_loc
-#define T_NXT ns_t_nxt
-#define T_EID ns_t_eid
-#define T_NIMLOC ns_t_nimloc
-#define T_SRV ns_t_srv
-#define T_ATMA ns_t_atma
-#define T_NAPTR ns_t_naptr
-#define T_KX ns_t_kx
-#define T_CERT ns_t_cert
-#define T_A6 ns_t_a6
-#define T_DNAME ns_t_dname
-#define T_SINK ns_t_sink
-#define T_OPT ns_t_opt
-#define T_APL ns_t_apl
-#define T_DS ns_t_ds
-#define T_SSHFP ns_t_sshfp
-#define T_RRSIG ns_t_rrsig
-#define T_NSEC ns_t_nsec
-#define T_DNSKEY ns_t_dnskey
-#define T_TKEY ns_t_tkey
-#define T_TSIG ns_t_tsig
-#define T_IXFR ns_t_ixfr
-#define T_AXFR ns_t_axfr
-#define T_MAILB ns_t_mailb
-#define T_MAILA ns_t_maila
-#define T_CAA ns_t_caa
-#define T_ANY ns_t_any
-
-#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 */
diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc
index 58bfea1b30d..d54e7c60cff 100644
--- a/src/cares_wrap.cc
+++ b/src/cares_wrap.cc
@@ -39,15 +39,7 @@
# include <netdb.h>
#endif // __POSIX__
-#if defined(__ANDROID__) || \
- defined(__MINGW32__) || \
- defined(__OpenBSD__) || \
- defined(_MSC_VER)
-
-# include <nameser.h>
-#else
-# include <arpa/nameser.h>
-#endif
+# include <ares_nameser.h>
// OpenBSD does not define these
#ifndef AI_ALL