Skip to content

Commit

Permalink
deps: sync with upstream c-ares/c-ares@bba4dc5
Browse files Browse the repository at this point in the history
Fixes: #1676
PR-URL: #1678
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
  • Loading branch information
bnoordhuis committed May 12, 2015
1 parent 36cdc7c commit 7e1c0e7
Show file tree
Hide file tree
Showing 21 changed files with 182 additions and 185 deletions.
5 changes: 2 additions & 3 deletions deps/cares/cares.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
'direct_dependent_settings': {
'include_dirs': [ 'include' ]
},
'defines': [ 'HAVE_CONFIG_H' ],
'sources': [
'common.gypi',
'include/ares.h',
Expand Down Expand Up @@ -96,7 +95,6 @@
'src/inet_ntop.c',
'src/ares_inet_net_pton.h',
'src/setup_once.h',
'src/windows_port.c'
],
'conditions': [
[ 'library=="static_library"', {
Expand All @@ -107,7 +105,7 @@
[ 'OS=="win"', {
'include_dirs': [ 'config/win32' ],
'sources': [
'config/win32/ares_config.h',
'src/config-win32.h',
'src/windows_port.c',
'src/ares_getenv.c',
'src/ares_iphlpapi.h',
Expand All @@ -126,6 +124,7 @@
'-Wextra',
'-Wno-unused-parameter'
],
'defines': [ 'HAVE_CONFIG_H' ],
}],
[ 'OS not in "win android"', {
'cflags': [
Expand Down
51 changes: 1 addition & 50 deletions deps/cares/include/ares.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,55 +29,8 @@
# define WIN32
#endif

/*************************** libuv patch ***************/

/*
* We want to avoid autoconf altogether since there are a finite number of
* operating systems and simply build c-ares. Therefore we do not want the
* configurations provided by ares_build.h since we are always statically
* linking c-ares into libuv. Having a system dependent ares_build.h forces
* all users of ares.h to include the correct ares_build.h. We do not care
* about the linking checks provided by ares_rules.h. This would complicate
* the libuv build process.
*/


#if defined(WIN32)
/* Configure process defines this to 1 when it finds out that system */
/* header file ws2tcpip.h must be included by the external interface. */
/* #undef CARES_PULL_WS2TCPIP_H */
# include <winsock2.h>
# include <ws2tcpip.h>
# include <windows.h>

#else /* Not Windows */

# include <sys/time.h>
# include <sys/types.h>
# include <sys/socket.h>
#endif

#if 0
/* The size of `long', as computed by sizeof. */
#define CARES_SIZEOF_LONG 4
#endif

/* Integral data type used for ares_socklen_t. */
#define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t

#if 0
/* The size of `ares_socklen_t', as computed by sizeof. */
#define CARES_SIZEOF_ARES_SOCKLEN_T 4
#endif

/* Data type definition of ares_socklen_t. */
typedef int ares_socklen_t;

#if 0 /* libuv disabled */
#include "ares_rules.h" /* c-ares rules enforcement */
#endif

/*********************** end libuv patch ***************/
typedef unsigned ares_socklen_t;

#include <sys/types.h>

Expand Down Expand Up @@ -520,8 +473,6 @@ struct ares_txt_reply {
struct ares_txt_reply *next;
unsigned char *txt;
size_t length; /* length excludes null termination */
unsigned char record_start; /* 1 - if start of new record
* 0 - if a chunk in the same record */
};

struct ares_naptr_reply {
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 @@ -7,11 +7,11 @@

#define ARES_VERSION_MAJOR 1
#define ARES_VERSION_MINOR 10
#define ARES_VERSION_PATCH 0
#define ARES_VERSION_PATCH 1
#define ARES_VERSION ((ARES_VERSION_MAJOR<<16)|\
(ARES_VERSION_MINOR<<8)|\
(ARES_VERSION_PATCH))
#define ARES_VERSION_STR "1.10.0-DEV"
#define ARES_VERSION_STR "1.10.1-DEV"

#if (ARES_VERSION >= 0x010700)
# define CARES_HAVE_ARES_LIBRARY_INIT 1
Expand Down
5 changes: 4 additions & 1 deletion deps/cares/src/ares__read_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ int ares__read_line(FILE *fp, char **buf, size_t *bufsize)
/* Allocate more space. */
newbuf = realloc(*buf, *bufsize * 2);
if (!newbuf)
return ARES_ENOMEM;
{
free(*buf);
return ARES_ENOMEM;
}
*buf = newbuf;
*bufsize *= 2;
}
Expand Down
5 changes: 3 additions & 2 deletions deps/cares/src/ares_gethostbyname.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ static void host_callback(void *arg, int status, int timeouts,
else if (hquery->sent_family == AF_INET6)
{
status = ares_parse_aaaa_reply(abuf, alen, &host, NULL, NULL);
if ((status == ARES_ENODATA || status == ARES_EBADRESP) &&
hquery->want_family == AF_UNSPEC) {
if ((status == ARES_ENODATA || status == ARES_EBADRESP ||
(status == ARES_SUCCESS && host && host->h_addr_list[0] == NULL)) &&
hquery->want_family == AF_UNSPEC) {
/* The query returned something but either there were no AAAA
records (e.g. just CNAME) or the response was malformed. Try
looking up A instead. */
Expand Down
20 changes: 14 additions & 6 deletions deps/cares/src/ares_getnameinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ static char *lookup_service(unsigned short port, int flags,
struct servent se;
#endif
char tmpbuf[4096];
char *name;
size_t name_len;

if (port)
{
Expand Down Expand Up @@ -323,14 +325,20 @@ static char *lookup_service(unsigned short port, int flags,
#endif
}
if (sep && sep->s_name)
/* get service name */
strcpy(tmpbuf, sep->s_name);
{
/* get service name */
name = sep->s_name;
}
else
/* get port as a string */
sprintf(tmpbuf, "%u", (unsigned int)ntohs(port));
if (strlen(tmpbuf) < buflen)
{
/* get port as a string */
sprintf(tmpbuf, "%u", (unsigned int)ntohs(port));
name = tmpbuf;
}
name_len = strlen(name);
if (name_len < buflen)
/* return it if buffer big enough */
strcpy(buf, tmpbuf);
memcpy(buf, name, name_len + 1);
else
/* avoid reusing previous one */
buf[0] = '\0';
Expand Down
8 changes: 3 additions & 5 deletions deps/cares/src/ares_getsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ int ares_getsock(ares_channel channel,
/* Are there any active queries? */
int active_queries = !ares__is_list_empty(&(channel->all_queries));

for (i = 0;
(i < channel->nservers) && (sockindex < ARES_GETSOCK_MAXNUM);
i++)
for (i = 0; i < channel->nservers; i++)
{
server = &channel->servers[i];
/* We only need to register interest in UDP sockets if we have
* outstanding queries.
*/
if (active_queries && server->udp_socket != ARES_SOCKET_BAD)
{
if(sockindex >= numsocks)
if(sockindex >= numsocks || sockindex >= ARES_GETSOCK_MAXNUM)
break;
socks[sockindex] = server->udp_socket;
bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
Expand All @@ -52,7 +50,7 @@ int ares_getsock(ares_channel channel,
*/
if (server->tcp_socket != ARES_SOCKET_BAD)
{
if(sockindex >= numsocks)
if(sockindex >= numsocks || sockindex >= ARES_GETSOCK_MAXNUM)
break;
socks[sockindex] = server->tcp_socket;
bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
Expand Down
13 changes: 10 additions & 3 deletions deps/cares/src/ares_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ int ares_dup(ares_channel *dest, ares_channel src)
which is most of them */
rc = ares_save_options(src, &opts, &optmask);
if(rc)
{
ares_destroy_options(&opts);
return rc;
}

/* Then create the new channel with those options */
rc = ares_init_options(dest, &opts, optmask);
Expand Down Expand Up @@ -1158,20 +1161,24 @@ static int init_by_resolv_conf(ares_channel channel)
FILE *fp;
size_t linesize;
int error;
int update_domains;

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

/* Only update search domains if they're not already specified */
update_domains = (channel->ndomains == -1);

fp = fopen(PATH_RESOLV_CONF, "r");
if (fp) {
while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
{
if ((p = try_config(line, "domain", ';')))
if ((p = try_config(line, "domain", ';')) && update_domains)
status = config_domain(channel, p);
else if ((p = try_config(line, "lookup", ';')) && !channel->lookups)
status = config_lookup(channel, p, "bind", "file");
else if ((p = try_config(line, "search", ';')))
else if ((p = try_config(line, "search", ';')) && update_domains)
status = set_search(channel, p);
else if ((p = try_config(line, "nameserver", ';')) &&
channel->nservers == -1)
Expand Down Expand Up @@ -1410,7 +1417,7 @@ static int init_by_defaults(ares_channel channel)
goto error;
}

} WHILE_FALSE;
} while (res != 0);

dot = strchr(hostname, '.');
if (dot) {
Expand Down
2 changes: 1 addition & 1 deletion deps/cares/src/ares_ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct addrinfo
#endif
#endif

/* Defined in ares_net_pton.c for no particular reason. */
/* Defined in inet_net_pton.c for no particular reason. */
extern const struct ares_in6_addr ares_in6addr_any; /* :: */


Expand Down
4 changes: 2 additions & 2 deletions deps/cares/src/ares_library_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static int ares_win32_init(void)
#ifdef USE_WINSOCK

hnd_iphlpapi = 0;
hnd_iphlpapi = LoadLibraryW(L"iphlpapi.dll");
hnd_iphlpapi = LoadLibrary("iphlpapi.dll");
if (!hnd_iphlpapi)
return ARES_ELOADIPHLPAPI;

Expand Down Expand Up @@ -73,7 +73,7 @@ static int ares_win32_init(void)
*/

hnd_advapi32 = 0;
hnd_advapi32 = LoadLibraryW(L"advapi32.dll");
hnd_advapi32 = LoadLibrary("advapi32.dll");
if (hnd_advapi32)
{
ares_fpSystemFunction036 = (fpSystemFunction036_t)
Expand Down
48 changes: 41 additions & 7 deletions deps/cares/src/ares_nowarn.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

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

#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif

#if defined(__INTEL_COMPILER) && defined(__unix__)

#ifdef HAVE_NETINET_IN_H
Expand All @@ -36,13 +40,43 @@

#include "ares_nowarn.h"

#define CARES_MASK_USHORT (~(unsigned short) 0)
#define CARES_MASK_UINT (~(unsigned int) 0)
#define CARES_MASK_ULONG (~(unsigned long) 0)
#if (SIZEOF_SHORT == 2)
# define CARES_MASK_SSHORT 0x7FFF
# define CARES_MASK_USHORT 0xFFFF
#elif (SIZEOF_SHORT == 4)
# define CARES_MASK_SSHORT 0x7FFFFFFF
# define CARES_MASK_USHORT 0xFFFFFFFF
#elif (SIZEOF_SHORT == 8)
# define CARES_MASK_SSHORT 0x7FFFFFFFFFFFFFFF
# define CARES_MASK_USHORT 0xFFFFFFFFFFFFFFFF
#else
# error "SIZEOF_SHORT not defined"
#endif

#define CARES_MASK_SSHORT (CARES_MASK_USHORT >> 1)
#define CARES_MASK_SINT (CARES_MASK_UINT >> 1)
#define CARES_MASK_SLONG (CARES_MASK_ULONG >> 1)
#if (SIZEOF_INT == 2)
# define CARES_MASK_SINT 0x7FFF
# define CARES_MASK_UINT 0xFFFF
#elif (SIZEOF_INT == 4)
# define CARES_MASK_SINT 0x7FFFFFFF
# define CARES_MASK_UINT 0xFFFFFFFF
#elif (SIZEOF_INT == 8)
# define CARES_MASK_SINT 0x7FFFFFFFFFFFFFFF
# define CARES_MASK_UINT 0xFFFFFFFFFFFFFFFF
#elif (SIZEOF_INT == 16)
# define CARES_MASK_SINT 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
# define CARES_MASK_UINT 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
#else
# error "SIZEOF_INT not defined"
#endif

#ifndef HAVE_LIMITS_H
/* systems without <limits.h> we guess have 32 bit longs */
#define CARES_MASK_SLONG 0x7FFFFFFFL
#define CARES_MASK_ULONG 0xFFFFFFFFUL
#else
#define CARES_MASK_ULONG ULONG_MAX
#define CARES_MASK_SLONG LONG_MAX
#endif

/*
** unsigned size_t to signed long
Expand Down
3 changes: 3 additions & 0 deletions deps/cares/src/ares_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ int ares_set_servers_csv(ares_channel channel,
return ARES_SUCCESS; /* blank all servers */

csv = malloc(i + 2);
if (!csv)
return ARES_ENOMEM;

strcpy(csv, _csv);
if (csv[i-1] != ',') { /* make parsing easier by ensuring ending ',' */
csv[i] = ',';
Expand Down
5 changes: 4 additions & 1 deletion deps/cares/src/ares_parse_soa_reply.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
/* allocate result struct */
soa = ares_malloc_data(ARES_DATATYPE_SOA_REPLY);
if (!soa)
return ARES_ENOMEM;
{
status = ARES_ENOMEM;
goto failed_stat;
}

/* nsname */
status = ares__expand_name_for_response(aptr, abuf, alen, &soa->nsname, &len);
Expand Down
5 changes: 2 additions & 3 deletions deps/cares/src/ares_parse_txt_reply.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
break;
}

++strptr;

/* Allocate storage for this TXT answer appending it to the list */
txt_curr = ares_malloc_data(ARES_DATATYPE_TXT_REPLY);
if (!txt_curr)
Expand All @@ -150,16 +152,13 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
}
txt_last = txt_curr;

txt_curr->record_start = strptr == aptr;
txt_curr->length = substr_len;
txt_curr->txt = malloc (substr_len + 1/* Including null byte */);
if (txt_curr->txt == NULL)
{
status = ARES_ENOMEM;
break;
}

++strptr;
memcpy ((char *) txt_curr->txt, strptr, substr_len);

/* Make sure we NULL-terminate */
Expand Down
Loading

0 comments on commit 7e1c0e7

Please sign in to comment.