Skip to content

Commit 7e1c0e7

Browse files
committed
deps: sync with upstream c-ares/c-ares@bba4dc5
Fixes: #1676 PR-URL: #1678 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent 36cdc7c commit 7e1c0e7

21 files changed

+182
-185
lines changed

deps/cares/cares.gyp

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
'direct_dependent_settings': {
2727
'include_dirs': [ 'include' ]
2828
},
29-
'defines': [ 'HAVE_CONFIG_H' ],
3029
'sources': [
3130
'common.gypi',
3231
'include/ares.h',
@@ -96,7 +95,6 @@
9695
'src/inet_ntop.c',
9796
'src/ares_inet_net_pton.h',
9897
'src/setup_once.h',
99-
'src/windows_port.c'
10098
],
10199
'conditions': [
102100
[ 'library=="static_library"', {
@@ -107,7 +105,7 @@
107105
[ 'OS=="win"', {
108106
'include_dirs': [ 'config/win32' ],
109107
'sources': [
110-
'config/win32/ares_config.h',
108+
'src/config-win32.h',
111109
'src/windows_port.c',
112110
'src/ares_getenv.c',
113111
'src/ares_iphlpapi.h',
@@ -126,6 +124,7 @@
126124
'-Wextra',
127125
'-Wno-unused-parameter'
128126
],
127+
'defines': [ 'HAVE_CONFIG_H' ],
129128
}],
130129
[ 'OS not in "win android"', {
131130
'cflags': [

deps/cares/include/ares.h

+1-50
Original file line numberDiff line numberDiff line change
@@ -29,55 +29,8 @@
2929
# define WIN32
3030
#endif
3131

32-
/*************************** libuv patch ***************/
33-
34-
/*
35-
* We want to avoid autoconf altogether since there are a finite number of
36-
* operating systems and simply build c-ares. Therefore we do not want the
37-
* configurations provided by ares_build.h since we are always statically
38-
* linking c-ares into libuv. Having a system dependent ares_build.h forces
39-
* all users of ares.h to include the correct ares_build.h. We do not care
40-
* about the linking checks provided by ares_rules.h. This would complicate
41-
* the libuv build process.
42-
*/
43-
44-
45-
#if defined(WIN32)
46-
/* Configure process defines this to 1 when it finds out that system */
47-
/* header file ws2tcpip.h must be included by the external interface. */
48-
/* #undef CARES_PULL_WS2TCPIP_H */
49-
# include <winsock2.h>
50-
# include <ws2tcpip.h>
51-
# include <windows.h>
52-
53-
#else /* Not Windows */
54-
55-
# include <sys/time.h>
56-
# include <sys/types.h>
57-
# include <sys/socket.h>
58-
#endif
59-
60-
#if 0
61-
/* The size of `long', as computed by sizeof. */
62-
#define CARES_SIZEOF_LONG 4
63-
#endif
64-
65-
/* Integral data type used for ares_socklen_t. */
66-
#define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t
67-
68-
#if 0
69-
/* The size of `ares_socklen_t', as computed by sizeof. */
70-
#define CARES_SIZEOF_ARES_SOCKLEN_T 4
71-
#endif
72-
7332
/* Data type definition of ares_socklen_t. */
74-
typedef int ares_socklen_t;
75-
76-
#if 0 /* libuv disabled */
77-
#include "ares_rules.h" /* c-ares rules enforcement */
78-
#endif
79-
80-
/*********************** end libuv patch ***************/
33+
typedef unsigned ares_socklen_t;
8134

8235
#include <sys/types.h>
8336

@@ -520,8 +473,6 @@ struct ares_txt_reply {
520473
struct ares_txt_reply *next;
521474
unsigned char *txt;
522475
size_t length; /* length excludes null termination */
523-
unsigned char record_start; /* 1 - if start of new record
524-
* 0 - if a chunk in the same record */
525476
};
526477

527478
struct ares_naptr_reply {

deps/cares/include/ares_version.h

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

88
#define ARES_VERSION_MAJOR 1
99
#define ARES_VERSION_MINOR 10
10-
#define ARES_VERSION_PATCH 0
10+
#define ARES_VERSION_PATCH 1
1111
#define ARES_VERSION ((ARES_VERSION_MAJOR<<16)|\
1212
(ARES_VERSION_MINOR<<8)|\
1313
(ARES_VERSION_PATCH))
14-
#define ARES_VERSION_STR "1.10.0-DEV"
14+
#define ARES_VERSION_STR "1.10.1-DEV"
1515

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

deps/cares/src/ares__read_line.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ int ares__read_line(FILE *fp, char **buf, size_t *bufsize)
6161
/* Allocate more space. */
6262
newbuf = realloc(*buf, *bufsize * 2);
6363
if (!newbuf)
64-
return ARES_ENOMEM;
64+
{
65+
free(*buf);
66+
return ARES_ENOMEM;
67+
}
6568
*buf = newbuf;
6669
*bufsize *= 2;
6770
}

deps/cares/src/ares_gethostbyname.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ static void host_callback(void *arg, int status, int timeouts,
188188
else if (hquery->sent_family == AF_INET6)
189189
{
190190
status = ares_parse_aaaa_reply(abuf, alen, &host, NULL, NULL);
191-
if ((status == ARES_ENODATA || status == ARES_EBADRESP) &&
192-
hquery->want_family == AF_UNSPEC) {
191+
if ((status == ARES_ENODATA || status == ARES_EBADRESP ||
192+
(status == ARES_SUCCESS && host && host->h_addr_list[0] == NULL)) &&
193+
hquery->want_family == AF_UNSPEC) {
193194
/* The query returned something but either there were no AAAA
194195
records (e.g. just CNAME) or the response was malformed. Try
195196
looking up A instead. */

deps/cares/src/ares_getnameinfo.c

+14-6
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ static char *lookup_service(unsigned short port, int flags,
281281
struct servent se;
282282
#endif
283283
char tmpbuf[4096];
284+
char *name;
285+
size_t name_len;
284286

285287
if (port)
286288
{
@@ -323,14 +325,20 @@ static char *lookup_service(unsigned short port, int flags,
323325
#endif
324326
}
325327
if (sep && sep->s_name)
326-
/* get service name */
327-
strcpy(tmpbuf, sep->s_name);
328+
{
329+
/* get service name */
330+
name = sep->s_name;
331+
}
328332
else
329-
/* get port as a string */
330-
sprintf(tmpbuf, "%u", (unsigned int)ntohs(port));
331-
if (strlen(tmpbuf) < buflen)
333+
{
334+
/* get port as a string */
335+
sprintf(tmpbuf, "%u", (unsigned int)ntohs(port));
336+
name = tmpbuf;
337+
}
338+
name_len = strlen(name);
339+
if (name_len < buflen)
332340
/* return it if buffer big enough */
333-
strcpy(buf, tmpbuf);
341+
memcpy(buf, name, name_len + 1);
334342
else
335343
/* avoid reusing previous one */
336344
buf[0] = '\0';

deps/cares/src/ares_getsock.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,15 @@ int ares_getsock(ares_channel channel,
3030
/* Are there any active queries? */
3131
int active_queries = !ares__is_list_empty(&(channel->all_queries));
3232

33-
for (i = 0;
34-
(i < channel->nservers) && (sockindex < ARES_GETSOCK_MAXNUM);
35-
i++)
33+
for (i = 0; i < channel->nservers; i++)
3634
{
3735
server = &channel->servers[i];
3836
/* We only need to register interest in UDP sockets if we have
3937
* outstanding queries.
4038
*/
4139
if (active_queries && server->udp_socket != ARES_SOCKET_BAD)
4240
{
43-
if(sockindex >= numsocks)
41+
if(sockindex >= numsocks || sockindex >= ARES_GETSOCK_MAXNUM)
4442
break;
4543
socks[sockindex] = server->udp_socket;
4644
bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
@@ -52,7 +50,7 @@ int ares_getsock(ares_channel channel,
5250
*/
5351
if (server->tcp_socket != ARES_SOCKET_BAD)
5452
{
55-
if(sockindex >= numsocks)
53+
if(sockindex >= numsocks || sockindex >= ARES_GETSOCK_MAXNUM)
5654
break;
5755
socks[sockindex] = server->tcp_socket;
5856
bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);

deps/cares/src/ares_init.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ int ares_dup(ares_channel *dest, ares_channel src)
266266
which is most of them */
267267
rc = ares_save_options(src, &opts, &optmask);
268268
if(rc)
269+
{
270+
ares_destroy_options(&opts);
269271
return rc;
272+
}
270273

271274
/* Then create the new channel with those options */
272275
rc = ares_init_options(dest, &opts, optmask);
@@ -1158,20 +1161,24 @@ static int init_by_resolv_conf(ares_channel channel)
11581161
FILE *fp;
11591162
size_t linesize;
11601163
int error;
1164+
int update_domains;
11611165

11621166
/* Don't read resolv.conf and friends if we don't have to */
11631167
if (ARES_CONFIG_CHECK(channel))
11641168
return ARES_SUCCESS;
11651169

1170+
/* Only update search domains if they're not already specified */
1171+
update_domains = (channel->ndomains == -1);
1172+
11661173
fp = fopen(PATH_RESOLV_CONF, "r");
11671174
if (fp) {
11681175
while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
11691176
{
1170-
if ((p = try_config(line, "domain", ';')))
1177+
if ((p = try_config(line, "domain", ';')) && update_domains)
11711178
status = config_domain(channel, p);
11721179
else if ((p = try_config(line, "lookup", ';')) && !channel->lookups)
11731180
status = config_lookup(channel, p, "bind", "file");
1174-
else if ((p = try_config(line, "search", ';')))
1181+
else if ((p = try_config(line, "search", ';')) && update_domains)
11751182
status = set_search(channel, p);
11761183
else if ((p = try_config(line, "nameserver", ';')) &&
11771184
channel->nservers == -1)
@@ -1410,7 +1417,7 @@ static int init_by_defaults(ares_channel channel)
14101417
goto error;
14111418
}
14121419

1413-
} WHILE_FALSE;
1420+
} while (res != 0);
14141421

14151422
dot = strchr(hostname, '.');
14161423
if (dot) {

deps/cares/src/ares_ipv6.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct addrinfo
7171
#endif
7272
#endif
7373

74-
/* Defined in ares_net_pton.c for no particular reason. */
74+
/* Defined in inet_net_pton.c for no particular reason. */
7575
extern const struct ares_in6_addr ares_in6addr_any; /* :: */
7676

7777

deps/cares/src/ares_library_init.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static int ares_win32_init(void)
4545
#ifdef USE_WINSOCK
4646

4747
hnd_iphlpapi = 0;
48-
hnd_iphlpapi = LoadLibraryW(L"iphlpapi.dll");
48+
hnd_iphlpapi = LoadLibrary("iphlpapi.dll");
4949
if (!hnd_iphlpapi)
5050
return ARES_ELOADIPHLPAPI;
5151

@@ -73,7 +73,7 @@ static int ares_win32_init(void)
7373
*/
7474

7575
hnd_advapi32 = 0;
76-
hnd_advapi32 = LoadLibraryW(L"advapi32.dll");
76+
hnd_advapi32 = LoadLibrary("advapi32.dll");
7777
if (hnd_advapi32)
7878
{
7979
ares_fpSystemFunction036 = (fpSystemFunction036_t)

deps/cares/src/ares_nowarn.c

+41-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
/* Copyright (C) 2010-2012 by Daniel Stenberg
2+
/* Copyright (C) 2010-2013 by Daniel Stenberg
33
*
44
* Permission to use, copy, modify, and distribute this
55
* software and its documentation for any purpose and without
@@ -21,6 +21,10 @@
2121
# include <assert.h>
2222
#endif
2323

24+
#ifdef HAVE_LIMITS_H
25+
#include <limits.h>
26+
#endif
27+
2428
#if defined(__INTEL_COMPILER) && defined(__unix__)
2529

2630
#ifdef HAVE_NETINET_IN_H
@@ -36,13 +40,43 @@
3640

3741
#include "ares_nowarn.h"
3842

39-
#define CARES_MASK_USHORT (~(unsigned short) 0)
40-
#define CARES_MASK_UINT (~(unsigned int) 0)
41-
#define CARES_MASK_ULONG (~(unsigned long) 0)
43+
#if (SIZEOF_SHORT == 2)
44+
# define CARES_MASK_SSHORT 0x7FFF
45+
# define CARES_MASK_USHORT 0xFFFF
46+
#elif (SIZEOF_SHORT == 4)
47+
# define CARES_MASK_SSHORT 0x7FFFFFFF
48+
# define CARES_MASK_USHORT 0xFFFFFFFF
49+
#elif (SIZEOF_SHORT == 8)
50+
# define CARES_MASK_SSHORT 0x7FFFFFFFFFFFFFFF
51+
# define CARES_MASK_USHORT 0xFFFFFFFFFFFFFFFF
52+
#else
53+
# error "SIZEOF_SHORT not defined"
54+
#endif
4255

43-
#define CARES_MASK_SSHORT (CARES_MASK_USHORT >> 1)
44-
#define CARES_MASK_SINT (CARES_MASK_UINT >> 1)
45-
#define CARES_MASK_SLONG (CARES_MASK_ULONG >> 1)
56+
#if (SIZEOF_INT == 2)
57+
# define CARES_MASK_SINT 0x7FFF
58+
# define CARES_MASK_UINT 0xFFFF
59+
#elif (SIZEOF_INT == 4)
60+
# define CARES_MASK_SINT 0x7FFFFFFF
61+
# define CARES_MASK_UINT 0xFFFFFFFF
62+
#elif (SIZEOF_INT == 8)
63+
# define CARES_MASK_SINT 0x7FFFFFFFFFFFFFFF
64+
# define CARES_MASK_UINT 0xFFFFFFFFFFFFFFFF
65+
#elif (SIZEOF_INT == 16)
66+
# define CARES_MASK_SINT 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
67+
# define CARES_MASK_UINT 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
68+
#else
69+
# error "SIZEOF_INT not defined"
70+
#endif
71+
72+
#ifndef HAVE_LIMITS_H
73+
/* systems without <limits.h> we guess have 32 bit longs */
74+
#define CARES_MASK_SLONG 0x7FFFFFFFL
75+
#define CARES_MASK_ULONG 0xFFFFFFFFUL
76+
#else
77+
#define CARES_MASK_ULONG ULONG_MAX
78+
#define CARES_MASK_SLONG LONG_MAX
79+
#endif
4680

4781
/*
4882
** unsigned size_t to signed long

deps/cares/src/ares_options.c

+3
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ int ares_set_servers_csv(ares_channel channel,
158158
return ARES_SUCCESS; /* blank all servers */
159159

160160
csv = malloc(i + 2);
161+
if (!csv)
162+
return ARES_ENOMEM;
163+
161164
strcpy(csv, _csv);
162165
if (csv[i-1] != ',') { /* make parsing easier by ensuring ending ',' */
163166
csv[i] = ',';

deps/cares/src/ares_parse_soa_reply.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
8686
/* allocate result struct */
8787
soa = ares_malloc_data(ARES_DATATYPE_SOA_REPLY);
8888
if (!soa)
89-
return ARES_ENOMEM;
89+
{
90+
status = ARES_ENOMEM;
91+
goto failed_stat;
92+
}
9093

9194
/* nsname */
9295
status = ares__expand_name_for_response(aptr, abuf, alen, &soa->nsname, &len);

deps/cares/src/ares_parse_txt_reply.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
133133
break;
134134
}
135135

136+
++strptr;
137+
136138
/* Allocate storage for this TXT answer appending it to the list */
137139
txt_curr = ares_malloc_data(ARES_DATATYPE_TXT_REPLY);
138140
if (!txt_curr)
@@ -150,16 +152,13 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
150152
}
151153
txt_last = txt_curr;
152154

153-
txt_curr->record_start = strptr == aptr;
154155
txt_curr->length = substr_len;
155156
txt_curr->txt = malloc (substr_len + 1/* Including null byte */);
156157
if (txt_curr->txt == NULL)
157158
{
158159
status = ARES_ENOMEM;
159160
break;
160161
}
161-
162-
++strptr;
163162
memcpy ((char *) txt_curr->txt, strptr, substr_len);
164163

165164
/* Make sure we NULL-terminate */

0 commit comments

Comments
 (0)