Skip to content

Commit

Permalink
deps: update to c-ares 1.17.1
Browse files Browse the repository at this point in the history
PR-URL: #36207
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
lxdicted authored and richardlau committed Jul 26, 2021
1 parent 39e9cd5 commit e11a862
Show file tree
Hide file tree
Showing 18 changed files with 386 additions and 54 deletions.
1 change: 1 addition & 0 deletions deps/cares/cares.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
'src/ares__parse_into_addrinfo.c',
'src/ares_parse_aaaa_reply.c',
'src/ares_parse_a_reply.c',
'src/ares_parse_caa_reply.c',
'src/ares_parse_mx_reply.c',
'src/ares_parse_naptr_reply.c',
'src/ares_parse_ns_reply.c',
Expand Down
13 changes: 13 additions & 0 deletions deps/cares/include/ares.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,15 @@ struct ares_addr6ttl {
int ttl;
};

struct ares_caa_reply {
struct ares_caa_reply *next;
int critical;
unsigned char *property;
size_t plength; /* plength excludes null termination */
unsigned char *value;
size_t length; /* length excludes null termination */
};

struct ares_srv_reply {
struct ares_srv_reply *next;
char *host;
Expand Down Expand Up @@ -637,6 +646,10 @@ CARES_EXTERN int ares_parse_aaaa_reply(const unsigned char *abuf,
struct ares_addr6ttl *addrttls,
int *naddrttls);

CARES_EXTERN int ares_parse_caa_reply(const unsigned char* abuf,
int alen,
struct ares_caa_reply** caa_out);

CARES_EXTERN int ares_parse_ptr_reply(const unsigned char *abuf,
int alen,
const void *addr,
Expand Down
4 changes: 2 additions & 2 deletions deps/cares/include/ares_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#define ARES_COPYRIGHT "2004 - 2020 Daniel Stenberg, <daniel@haxx.se>."

#define ARES_VERSION_MAJOR 1
#define ARES_VERSION_MINOR 16
#define ARES_VERSION_MINOR 17
#define ARES_VERSION_PATCH 1
#define ARES_VERSION ((ARES_VERSION_MAJOR<<16)|\
(ARES_VERSION_MINOR<<8)|\
(ARES_VERSION_PATCH))
#define ARES_VERSION_STR "1.16.1"
#define ARES_VERSION_STR "1.17.1"

#if (ARES_VERSION >= 0x010700)
# define CARES_HAVE_ARES_LIBRARY_INIT 1
Expand Down
7 changes: 7 additions & 0 deletions deps/cares/include/nameser.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typedef enum __ns_type {
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;

Expand Down Expand Up @@ -204,8 +205,14 @@ typedef enum __ns_rcode {
#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 */
8 changes: 6 additions & 2 deletions deps/cares/src/ares__readaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ int ares__readaddrinfo(FILE *fp,
continue;
}

/* Zero-out 'addr' struct, as there are members that we may not set, especially
* for ipv6. We don't want garbage data */
memset(&addr, 0, sizeof(addr));

/*
* Convert address string to network address for the requested families.
* Actual address family possible values are AF_INET and AF_INET6 only.
Expand All @@ -179,7 +183,7 @@ int ares__readaddrinfo(FILE *fp,
}

node->ai_family = addr.sa.sa_family = AF_INET;
node->ai_addrlen = sizeof(sizeof(addr.sa4));
node->ai_addrlen = sizeof(addr.sa4);
node->ai_addr = ares_malloc(sizeof(addr.sa4));
if (!node->ai_addr)
{
Expand All @@ -200,7 +204,7 @@ int ares__readaddrinfo(FILE *fp,
}

node->ai_family = addr.sa.sa_family = AF_INET6;
node->ai_addrlen = sizeof(sizeof(addr.sa6));
node->ai_addrlen = sizeof(addr.sa6);
node->ai_addr = ares_malloc(sizeof(addr.sa6));
if (!node->ai_addr)
{
Expand Down
21 changes: 11 additions & 10 deletions deps/cares/src/ares__sortaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ struct addrinfo_sort_elem
#define ARES_IN6_IS_ADDR_6BONE(a) \
(((a)->s6_addr[0] == 0x3f) && ((a)->s6_addr[1] == 0xfe))


static int get_scope(const struct sockaddr *addr)
{
if (addr->sa_family == AF_INET6)
{
const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
const struct sockaddr_in6 *addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
if (IN6_IS_ADDR_MULTICAST(&addr6->sin6_addr))
{
return ARES_IPV6_ADDR_MC_SCOPE(&addr6->sin6_addr);
Expand All @@ -114,7 +115,7 @@ static int get_scope(const struct sockaddr *addr)
}
else if (addr->sa_family == AF_INET)
{
const struct sockaddr_in *addr4 = (const struct sockaddr_in *)addr;
const struct sockaddr_in *addr4 = CARES_INADDR_CAST(const struct sockaddr_in *, addr);
unsigned long int na = ntohl(addr4->sin_addr.s_addr);
if (ARES_IN_LOOPBACK(na) || /* 127.0.0.0/8 */
(na & 0xffff0000) == 0xa9fe0000) /* 169.254.0.0/16 */
Expand Down Expand Up @@ -149,7 +150,7 @@ static int get_label(const struct sockaddr *addr)
}
else if (addr->sa_family == AF_INET6)
{
const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
const struct sockaddr_in6 *addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr))
{
return 0;
Expand Down Expand Up @@ -210,7 +211,7 @@ static int get_precedence(const struct sockaddr *addr)
}
else if (addr->sa_family == AF_INET6)
{
const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr;
const struct sockaddr_in6 *addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr))
{
return 50;
Expand Down Expand Up @@ -353,10 +354,10 @@ static int rfc6724_compare(const void *ptr1, const void *ptr2)
{
const struct sockaddr_in6 *a1_src = &a1->src_addr.sa6;
const struct sockaddr_in6 *a1_dst =
(const struct sockaddr_in6 *)a1->ai->ai_addr;
CARES_INADDR_CAST(const struct sockaddr_in6 *, a1->ai->ai_addr);
const struct sockaddr_in6 *a2_src = &a2->src_addr.sa6;
const struct sockaddr_in6 *a2_dst =
(const struct sockaddr_in6 *)a2->ai->ai_addr;
CARES_INADDR_CAST(const struct sockaddr_in6 *, a2->ai->ai_addr);
prefixlen1 = common_prefix_len(&a1_src->sin6_addr, &a1_dst->sin6_addr);
prefixlen2 = common_prefix_len(&a2_src->sin6_addr, &a2_dst->sin6_addr);
if (prefixlen1 != prefixlen2)
Expand Down Expand Up @@ -384,7 +385,7 @@ static int find_src_addr(ares_channel channel,
const struct sockaddr *addr,
struct sockaddr *src_addr)
{
int sock;
ares_socket_t sock;
int ret;
ares_socklen_t len;

Expand All @@ -402,7 +403,7 @@ static int find_src_addr(ares_channel channel,
}

sock = ares__open_socket(channel, addr->sa_family, SOCK_DGRAM, IPPROTO_UDP);
if (sock == -1)
if (sock == ARES_SOCKET_BAD)
{
if (errno == EAFNOSUPPORT)
{
Expand All @@ -426,7 +427,7 @@ static int find_src_addr(ares_channel channel,
return 0;
}

if (getsockname(sock, src_addr, &len) == -1)
if (getsockname(sock, src_addr, &len) != 0)
{
ares__close_socket(channel, sock);
return -1;
Expand Down Expand Up @@ -491,4 +492,4 @@ int ares__sortaddrinfo(ares_channel channel, struct ares_addrinfo_node *list_sen

ares_free(elems);
return ARES_SUCCESS;
}
}
18 changes: 18 additions & 0 deletions deps/cares/src/ares_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ void ares_free_data(void *dataptr)
ares_free(ptr->data.soa_reply.hostmaster);
break;

case ARES_DATATYPE_CAA_REPLY:

if (ptr->data.caa_reply.next)
next_data = ptr->data.caa_reply.next;
if (ptr->data.caa_reply.property)
ares_free(ptr->data.caa_reply.property);
if (ptr->data.caa_reply.value)
ares_free(ptr->data.caa_reply.value);
break;

default:
return;
}
Expand Down Expand Up @@ -174,6 +184,14 @@ void *ares_malloc_data(ares_datatype type)
ptr->data.txt_reply.length = 0;
break;

case ARES_DATATYPE_CAA_REPLY:
ptr->data.caa_reply.next = NULL;
ptr->data.caa_reply.plength = 0;
ptr->data.caa_reply.property = NULL;
ptr->data.caa_reply.length = 0;
ptr->data.caa_reply.value = NULL;
break;

case ARES_DATATYPE_ADDR_NODE:
ptr->data.addr_node.next = NULL;
ptr->data.addr_node.family = 0;
Expand Down
2 changes: 2 additions & 0 deletions deps/cares/src/ares_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef enum {
ARES_DATATYPE_OPTIONS, /* struct ares_options */
#endif
ARES_DATATYPE_ADDR_PORT_NODE, /* struct ares_addr_port_node - introduced in 1.11.0 */
ARES_DATATYPE_CAA_REPLY, /* struct ares_caa_reply - introduced in 1.17 */
ARES_DATATYPE_LAST /* not used - introduced in 1.7.0 */
} ares_datatype;

Expand Down Expand Up @@ -65,6 +66,7 @@ struct ares_data {
struct ares_mx_reply mx_reply;
struct ares_naptr_reply naptr_reply;
struct ares_soa_reply soa_reply;
struct ares_caa_reply caa_reply;
} data;
};

Expand Down
11 changes: 11 additions & 0 deletions deps/cares/src/ares_getaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ static int fake_addrinfo(const char *name,
}
}

node->ai_socktype = hints->ai_socktype;
node->ai_protocol = hints->ai_protocol;

callback(arg, ARES_SUCCESS, 0, ai);
return 1;
}
Expand All @@ -406,6 +409,8 @@ static void end_hquery(struct host_query *hquery, int status)
/* Set port into each address (resolved separately). */
while (next)
{
next->ai_socktype = hquery->hints.ai_socktype;
next->ai_protocol = hquery->hints.ai_protocol;
if (next->ai_family == AF_INET)
{
(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr))->sin_port = htons(hquery->port);
Expand Down Expand Up @@ -754,12 +759,18 @@ static int as_is_first(const struct host_query* hquery)
{
char* p;
int ndots = 0;
size_t nname = strlen(hquery->name);
for (p = hquery->name; *p; p++)
{
if (*p == '.')
{
ndots++;
}
}
if (nname && hquery->name[nname-1] == '.')
{
/* prevent ARES_EBADNAME for valid FQDN, where ndots < channel->ndots */
return 1;
}
return ndots >= hquery->channel->ndots;
}
1 change: 0 additions & 1 deletion deps/cares/src/ares_gethostbyaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ static int file_lookup(struct ares_addr *addr, struct hostent **host)
strcat(PATH_HOSTS, WIN_PATH_HOSTS);

#elif defined(WATT32)
extern const char *_w32_GetHostsFile (void);
const char *PATH_HOSTS = _w32_GetHostsFile();

if (!PATH_HOSTS)
Expand Down
15 changes: 9 additions & 6 deletions deps/cares/src/ares_gethostbyname.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static int fake_hostent(const char *name, int family,
struct in_addr in;
struct ares_in6_addr in6;

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

if (result)
family = AF_INET;
/*
* Set address family in case of failure,
* as we will try to convert it later afterwards
*/
family = result ? AF_INET : AF_INET6;
}
if (family == AF_INET6)
result = (ares_inet_pton(AF_INET6, name, &in6) < 1 ? 0 : 1);
Expand Down Expand Up @@ -383,7 +387,6 @@ static int file_lookup(const char *name, int family, struct hostent **host)
strcat(PATH_HOSTS, WIN_PATH_HOSTS);

#elif defined(WATT32)
extern const char *_w32_GetHostsFile (void);
const char *PATH_HOSTS = _w32_GetHostsFile();

if (!PATH_HOSTS)
Expand Down
20 changes: 4 additions & 16 deletions deps/cares/src/ares_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,6 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
int status = ARES_SUCCESS;
struct timeval now;

#ifdef CURLDEBUG
const char *env = getenv("CARES_MEMDEBUG");

if (env)
curl_memdebug(env);
env = getenv("CARES_MEMLIMIT");
if (env) {
char *endptr;
long num = strtol(env, &endptr, 10);
if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
curl_memlimit(num);
}
#endif

if (ares_library_initialized() != ARES_SUCCESS)
return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */

Expand Down Expand Up @@ -1611,7 +1597,8 @@ static int init_by_resolv_conf(ares_channel channel)
if (channel->nservers == -1) {
union res_sockaddr_union addr[MAXNS];
int nscount = res_getservers(&res, addr, MAXNS);
for (int i = 0; i < nscount; ++i) {
int i;
for (i = 0; i < nscount; ++i) {
char str[INET6_ADDRSTRLEN];
int config_status;
sa_family_t family = addr[i].sin.sin_family;
Expand Down Expand Up @@ -1639,8 +1626,9 @@ static int init_by_resolv_conf(ares_channel channel)
if (!channel->domains) {
status = ARES_ENOMEM;
} else {
int i;
channel->ndomains = entries;
for (int i = 0; i < channel->ndomains; ++i) {
for (i = 0; i < channel->ndomains; ++i) {
channel->domains[i] = ares_strdup(res.dnsrch[i]);
if (!channel->domains[i])
status = ARES_ENOMEM;
Expand Down
Loading

0 comments on commit e11a862

Please sign in to comment.