Skip to content

Commit

Permalink
deps: upgrade to c-ares v1.15.0
Browse files Browse the repository at this point in the history
Our out-of-tree patch from 2b6bb9f ("deps: c-ares float, win ipv6 bad
fec0 prefix") should no longer be necessary, c-ares now blacklists such
addresses itself.

PR-URL: #23854
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
bnoordhuis authored and targos committed Nov 6, 2018
1 parent eaea90b commit 0766369
Show file tree
Hide file tree
Showing 23 changed files with 662 additions and 285 deletions.
2 changes: 1 addition & 1 deletion deps/cares/LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# c-ares license

Copyright (c) 2007 - 2016, Daniel Stenberg with many contributors, see AUTHORS
Copyright (c) 2007 - 2018, Daniel Stenberg with many contributors, see AUTHORS
file.

Copyright 1998 by the Massachusetts Institute of Technology.
Expand Down
1 change: 1 addition & 0 deletions deps/cares/cares.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
'src/ares_strdup.c',
'src/ares_strdup.h',
'src/ares_strerror.c',
'src/ares_strsplit.c',
'src/ares_timeout.c',
'src/ares__timeval.c',
'src/ares_version.c',
Expand Down
2 changes: 2 additions & 0 deletions deps/cares/include/ares.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ extern "C" {
#define ARES_OPT_ROTATE (1 << 14)
#define ARES_OPT_EDNSPSZ (1 << 15)
#define ARES_OPT_NOROTATE (1 << 16)
#define ARES_OPT_RESOLVCONF (1 << 17)

/* Nameinfo flag values */
#define ARES_NI_NOFQDN (1 << 0)
Expand Down Expand Up @@ -270,6 +271,7 @@ struct ares_options {
struct apattern *sortlist;
int nsort;
int ednspsz;
char *resolvconf_path;
};

struct hostent;
Expand Down
12 changes: 5 additions & 7 deletions deps/cares/include/ares_build.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,14 @@
/* Data type definition of ares_ssize_t. */
#ifdef _WIN32
# ifdef _WIN64
typedef __int64 ares_ssize_t;
# define CARES_TYPEOF_ARES_SSIZE_T __int64
# else
typedef long ares_ssize_t;
# define CARES_TYPEOF_ARES_SSIZE_T long
# endif
#else
# ifdef CARES_TYPEOF_ARES_SSIZE_T
typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t;
# else
typedef ssize_t ares_ssize_t;
# endif
# define CARES_TYPEOF_ARES_SSIZE_T ssize_t
#endif

typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t;

#endif /* __CARES_BUILD_H */
2 changes: 1 addition & 1 deletion deps/cares/include/ares_rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

/*
* Verify that the size previously defined and expected for
* ares_socklen_t is actually the the same as the one reported
* ares_socklen_t is actually the same as the one reported
* by sizeof() at compile time.
*/

Expand Down
72 changes: 34 additions & 38 deletions deps/cares/src/RELEASE-NOTES
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@
c-ares version 1.14.0
c-ares version 1.15.0

Changes:
o android: Introduce new ares_library_init_android() call for Oreo support. [5]
o Add ares_init_options() configurability for path to resolv.conf file [1]
o Ability to exclude building of tools (adig, ahost, acountry) in CMake [3]
o Android: Support for domain search suffix [4]
o Report ARES_ENOTFOUND for .onion domain names as per RFC7686. [13]

Bug fixes:

o Fix patch for CVE-2017-1000381 to not be overly aggressive. [1]
o win32: Preserve DNS server order returned by Windows when sorting and exclude
DNS servers in legacy subnets. [2] [4]
o win32: Support most recent Visual Studio 2017
o gethostbyaddr should fail with ECANCELLED not ENOTFOUND when ares_cancel
is called. [3]
o win32: Exclude legacy ipv6 subnets [4]
o android: Applications compiled for Oreo can no longer use
__system_property_get and must use Java calls to retrieve DNS servers.
[5] [7]
o win32: Force use of ANSI functions [6]
o CMake minimum version is now 3.1
o ares_gethostbyname.3: fix callback status values [8]
o docs: Document WSAStartup requirement [9]
o Fix a typo in init_by_resolv_conf [10]
o Android JNI code leaks local references in some cases [11]
o Force using the ANSI versions of WinAPI functions [12]
o AIX build fix for trying to include both nameser_compat.h and
onameser_compat.h [2]
o Windows: Improve DNS suffixes extracting from WinNT registry [5]
o Fix modern GCC warnings [6]
o Apply the IPv6 server blacklist to all nameserver sources, not just Windows
[7]
o Fix warnings emitted by MSVC when using -W4 [8]
o Prevent changing name servers while queries are outstanding [9]
o Harden and rationalize c-ares timeout computation [10]
o Distribute ares_android.h [11]
o ares_set_servers_csv() on failure should not leave channel in a bad state
[12]
o Add missing docs to distribution

Thanks go to these friendly people for their efforts and contributions:

AC Thompson, Anna Henningsen, Antonio Tajuelo, Brad House, Brad Spencer,
Christian Ammer, Daniel Stenberg, David Drysdale, David Hotham, Felix Yan,
Gergely Nagy, Gregor Jasny, Jakub Hrozek, John Schember,
Konstantinos Sofokleous, Roman Teterin, Sergey Kolomenkin, Sheel Bedi,
(18 contributors)
@afalin, Andi Schnebinger, Ben Noordhuis, Brad House, Brad Spencer,
David Hotham, @flyingdutchman23, John Schember, Ruslan Baratov,
Sarat Addepalli, Tobias Nießen (11 contributors)

References to bug reports and discussions on issues:
[1] = https://github.com/c-ares/c-ares/issues/220
[2] = https://github.com/c-ares/c-ares/issues/224
[3] = https://github.com/c-ares/c-ares/issues/200
[4] = https://github.com/c-ares/c-ares/issues/207
[5] = https://github.com/c-ares/c-ares/pull/202
[6] = https://github.com/c-ares/c-ares/pull/201
[7] = https://github.com/c-ares/c-ares/pull/193
[8] = https://github.com/c-ares/c-ares/pull/192
[9] = https://github.com/c-ares/c-ares/pull/191
[10] = https://github.com/c-ares/c-ares/pull/187
[11] = https://c-ares.haxx.se/mail/c-ares-archive-2018-04/0000.shtml
[12] = https://c-ares.haxx.se/mail/c-ares-archive-2018-03/0000.shtml
[13] = https://github.com/c-ares/c-ares/issues/196

[1] = https://github.com/c-ares/c-ares/commit/18ea99
[2] = https://github.com/c-ares/c-ares/issues/150
[3] = https://github.com/c-ares/c-ares/pull/138
[4] = https://github.com/c-ares/c-ares/pull/144
[5] = https://github.com/c-ares/c-ares/pull/148
[6] = https://github.com/c-ares/c-ares/pull/142
[7] = https://github.com/c-ares/c-ares/pull/175
[8] = https://c-ares.haxx.se/mail/c-ares-archive-2011-06/0012.shtml
[9] = https://github.com/c-ares/c-ares/pull/180
[10] = https://github.com/c-ares/c-ares/pull/160
[11] = https://github.com/c-ares/c-ares/pull/175
[12] = https://github.com/c-ares/c-ares/pull/142
99 changes: 99 additions & 0 deletions deps/cares/src/ares_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ static jmethodID android_cm_active_net_mid = NULL;
static jmethodID android_cm_link_props_mid = NULL;
/* LinkProperties.getDnsServers */
static jmethodID android_lp_dns_servers_mid = NULL;
/* LinkProperties.getDomains */
static jmethodID android_lp_domains_mid = NULL;
/* List.size */
static jmethodID android_list_size_mid = NULL;
/* List.get */
Expand Down Expand Up @@ -139,6 +141,12 @@ int ares_library_init_android(jobject connectivity_manager)
if (android_lp_dns_servers_mid == NULL)
goto cleanup;

/* getDomains in API 21. */
android_lp_domains_mid = jni_get_method_id(env, obj_cls, "getDomains",
"()Ljava/lang/String;");
if (android_lp_domains_mid == NULL)
goto cleanup;

(*env)->DeleteLocalRef(env, obj_cls);
obj_cls = jni_get_class(env, "java/util/List");
if (obj_cls == NULL)
Expand Down Expand Up @@ -173,6 +181,7 @@ int ares_library_init_android(jobject connectivity_manager)
android_cm_active_net_mid = NULL;
android_cm_link_props_mid = NULL;
android_lp_dns_servers_mid = NULL;
android_lp_domains_mid = NULL;
android_list_size_mid = NULL;
android_list_get_mid = NULL;
android_ia_host_addr_mid = NULL;
Expand Down Expand Up @@ -213,6 +222,7 @@ void ares_library_cleanup_android(void)
android_cm_active_net_mid = NULL;
android_cm_link_props_mid = NULL;
android_lp_dns_servers_mid = NULL;
android_lp_domains_mid = NULL;
android_list_size_mid = NULL;
android_list_get_mid = NULL;
android_ia_host_addr_mid = NULL;
Expand Down Expand Up @@ -341,6 +351,95 @@ char **ares_get_android_server_list(size_t max_servers,
(*android_jvm)->DetachCurrentThread(android_jvm);
return dns_list;
}

char *ares_get_android_search_domains_list(void)
{
JNIEnv *env = NULL;
jobject active_network = NULL;
jobject link_properties = NULL;
jstring domains = NULL;
const char *domain;
int res;
size_t i;
size_t cnt = 0;
char *domain_list = NULL;
int need_detatch = 0;

if (android_jvm == NULL || android_connectivity_manager == NULL)
{
return NULL;
}

if (android_cm_active_net_mid == NULL || android_cm_link_props_mid == NULL ||
android_lp_domains_mid == NULL)
{
return NULL;
}

res = (*android_jvm)->GetEnv(android_jvm, (void **)&env, JNI_VERSION_1_6);
if (res == JNI_EDETACHED)
{
env = NULL;
res = (*android_jvm)->AttachCurrentThread(android_jvm, &env, NULL);
need_detatch = 1;
}
if (res != JNI_OK || env == NULL)
goto done;

/* JNI below is equivalent to this Java code.
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
ConnectivityManager cm = (ConnectivityManager)this.getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
Network an = cm.getActiveNetwork();
LinkProperties lp = cm.getLinkProperties(an);
String domains = lp.getDomains();
for (String domain: domains.split(",")) {
String d = domain;
}
Note: The JNI ConnectivityManager object and all method IDs were previously
initialized in ares_library_init_android.
*/

active_network = (*env)->CallObjectMethod(env, android_connectivity_manager,
android_cm_active_net_mid);
if (active_network == NULL)
goto done;

link_properties =
(*env)->CallObjectMethod(env, android_connectivity_manager,
android_cm_link_props_mid, active_network);
if (link_properties == NULL)
goto done;

/* Get the domains. It is a common separated list of domains to search. */
domains = (*env)->CallObjectMethod(env, link_properties,
android_lp_domains_mid);
if (domains == NULL)
goto done;

/* Split on , */
domain = (*env)->GetStringUTFChars(env, domains, 0);
domain_list = ares_strdup(domain);
(*env)->ReleaseStringUTFChars(env, domains, domain);
(*env)->DeleteLocalRef(env, domains);

done:
if ((*env)->ExceptionOccurred(env))
(*env)->ExceptionClear(env);

if (link_properties != NULL)
(*env)->DeleteLocalRef(env, link_properties);
if (active_network != NULL)
(*env)->DeleteLocalRef(env, active_network);

if (need_detatch)
(*android_jvm)->DetachCurrentThread(android_jvm);
return domain_list;
}
#else
/* warning: ISO C forbids an empty translation unit */
typedef int dummy_make_iso_compilers_happy;
Expand Down
1 change: 1 addition & 0 deletions deps/cares/src/ares_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#if defined(ANDROID) || defined(__ANDROID__)

char **ares_get_android_server_list(size_t max_servers, size_t *num_servers);
char *ares_get_android_search_domains_list(void);
void ares_library_cleanup_android(void);

#endif
Expand Down
6 changes: 5 additions & 1 deletion deps/cares/src/ares_create_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ int ares_create_query(const char *name, int dnsclass, int type,
size_t buflen;
unsigned char *buf;

/* Per RFC 7686, reject queries for ".onion" domain names with NXDOMAIN. */
if (ares__is_onion_domain(name))
return ARES_ENOTFOUND;

/* Set our results early, in case we bail out early with an error. */
*buflenp = 0;
*bufp = NULL;
Expand Down Expand Up @@ -188,7 +192,7 @@ int ares_create_query(const char *name, int dnsclass, int type,
* specified in RFC 1035 ("To simplify implementations, the total length of
* a domain name (i.e., label octets and label length octets) is restricted
* to 255 octets or less."). */
if (buflen > (MAXCDNAME + HFIXEDSZ + QFIXEDSZ +
if (buflen > (size_t)(MAXCDNAME + HFIXEDSZ + QFIXEDSZ +
(max_udp_size ? EDNSFIXEDSZ : 0))) {
ares_free (buf);
return ARES_EBADNAME;
Expand Down
7 changes: 6 additions & 1 deletion deps/cares/src/ares_destroy.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ void ares_destroy_options(struct ares_options *options)
ares_free(options->sortlist);
if(options->lookups)
ares_free(options->lookups);
if(options->resolvconf_path)
ares_free(options->resolvconf_path);
}

void ares_destroy(ares_channel channel)
Expand All @@ -44,7 +46,7 @@ void ares_destroy(ares_channel channel)
struct query *query;
struct list_node* list_head;
struct list_node* list_node;

if (!channel)
return;

Expand Down Expand Up @@ -85,6 +87,9 @@ void ares_destroy(ares_channel channel)
if (channel->lookups)
ares_free(channel->lookups);

if (channel->resolvconf_path)
ares_free(channel->resolvconf_path);

ares_free(channel);
}

Expand Down
11 changes: 11 additions & 0 deletions deps/cares/src/ares_gethostbyname.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ void ares_gethostbyname(ares_channel channel, const char *name, int family,
return;
}

/* Per RFC 7686, reject queries for ".onion" domain names with NXDOMAIN. */
if (ares__is_onion_domain(name))
{
callback(arg, ARES_ENOTFOUND, 0, NULL);
return;
}

if (fake_hostent(name, family, callback, arg))
return;

Expand Down Expand Up @@ -339,6 +346,10 @@ static int file_lookup(const char *name, int family, struct hostent **host)
int status;
int error;

/* Per RFC 7686, reject queries for ".onion" domain names with NXDOMAIN. */
if (ares__is_onion_domain(name))
return ARES_ENOTFOUND;

#ifdef WIN32
char PATH_HOSTS[MAX_PATH];
win_platform platform;
Expand Down
11 changes: 11 additions & 0 deletions deps/cares/src/ares_getnameinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,14 @@ STATIC_TESTABLE char *ares_striendstr(const char *s1, const char *s2)
}
return (char *)c1_begin;
}

int ares__is_onion_domain(const char *name)
{
if (ares_striendstr(name, ".onion"))
return 1;

if (ares_striendstr(name, ".onion."))
return 1;

return 0;
}
Loading

0 comments on commit 0766369

Please sign in to comment.