This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Upgrade c-ares to 1.7.4

  • Loading branch information...
ry committed Jan 12, 2011
1 parent 86160a8 commit fc634cd92c645f856cb9c773755cb0d08033517d
View
@@ -1,5 +1,24 @@
Changelog for the c-ares project
+Version 1.7.4 (December 9, 2010)
+
+Changed:
+
+ o local-bind: Support binding to local interface/IPs, see
+ ares_set_local_ip4, ares_set_local_ip6, ares_set_local_dev
+
+Fixed:
+
+ o memory leak in ares_getnameinfo
+ o add missing break that caused get_ares_servers to fail
+ o ares_parse_a_reply: fix CNAME response parsing
+ o init_by_options: don't copy an empty sortlist
+ o Replaced uint32_t with unsigned int to fix broken builds
+ on a couple of platforms
+ o Fix lookup with HOSTALIASES set
+ o adig: fix NAPTR parsing
+ o compiler warning cleanups
+
Version 1.7.3 (June 11, 2010)
Fixed:
View
@@ -1,12 +1,25 @@
-c-ares version 1.7.3
+c-ares version 1.7.4
+
+Changed:
+
+ o local-bind: Support binding to local interface/IPs, see
+ ares_set_local_ip4, ares_set_local_ip6, ares_set_local_dev
Fixed:
- o builds on Android
- o now includes all files necessary to build it (1.7.2 lacked a file)
+ o memory leak in ares_getnameinfo
+ o add missing break that caused get_ares_servers to fail
+ o ares_parse_a_reply: fix CNAME response parsing
+ o init_by_options: don't copy an empty sortlist
+ o Replaced uint32_t with unsigned int to fix broken builds
+ on a couple of platforms
+ o Fix lookup with HOSTALIASES set
+ o adig: fix NAPTR parsing
+ o compiler warning cleanups
Thanks go to these friendly people for their efforts and contributions:
- Yang Tse, Bogdan Vatra
+ Andrew C. Morrow, Ben Greear, Ben Noordhuis, Daniel Stenberg,
+ Guenter Knauf, Mike Crowe, Patrik Thunstrom, Yang Tse
Have fun!
View
@@ -313,6 +313,20 @@ CARES_EXTERN void ares_destroy(ares_channel channel);
CARES_EXTERN void ares_cancel(ares_channel channel);
+/* These next 3 configure local binding for the out-going socket
+ * connection. Use these to specify source IP and/or network device
+ * on multi-homed systems.
+ */
+CARES_EXTERN void ares_set_local_ip4(ares_channel channel, unsigned int local_ip);
+
+/* local_ip6 should be 16 bytes in length */
+CARES_EXTERN void ares_set_local_ip6(ares_channel channel,
+ const unsigned char* local_ip6);
+
+/* local_dev_name should be null terminated. */
+CARES_EXTERN void ares_set_local_dev(ares_channel channel,
+ const char* local_dev_name);
+
CARES_EXTERN void ares_set_socket_callback(ares_channel channel,
ares_sock_create_callback callback,
void *user_data);
@@ -496,6 +510,7 @@ CARES_EXTERN void ares_free_data(void *dataptr);
CARES_EXTERN const char *ares_strerror(int code);
+/* TODO: Hold port here as well. */
struct ares_addr_node {
struct ares_addr_node *next;
int family;
@@ -508,6 +523,10 @@ struct ares_addr_node {
CARES_EXTERN int ares_set_servers(ares_channel channel,
struct ares_addr_node *servers);
+/* Incomming string format: host[:port][,host[:port]]... */
+CARES_EXTERN int ares_set_servers_csv(ares_channel channel,
+ const char* servers);
+
CARES_EXTERN int ares_get_servers(ares_channel channel,
struct ares_addr_node **servers);
View
@@ -145,7 +145,8 @@ void *ares_malloc_data(ares_datatype type)
ptr->data.addr_node.next = NULL;
ptr->data.addr_node.family = 0;
memset(&ptr->data.addr_node.addrV6, 0,
- sizeof(ptr->data.addr_node.addrV6));
+ sizeof(ptr->data.addr_node.addrV6));
+ break;
default:
free(ptr);
@@ -265,11 +265,11 @@ static void ptr_rr_name(char *name, const struct ares_addr *addr)
if (addr->family == AF_INET)
{
unsigned long laddr = ntohl(addr->addrV4.s_addr);
- int a1 = (int)((laddr >> 24) & 0xff);
- int a2 = (int)((laddr >> 16) & 0xff);
- int a3 = (int)((laddr >> 8) & 0xff);
- int a4 = (int)(laddr & 0xff);
- sprintf(name, "%d.%d.%d.%d.in-addr.arpa", a4, a3, a2, a1);
+ unsigned long a1 = (laddr >> 24UL) & 0xFFUL;
+ unsigned long a2 = (laddr >> 16UL) & 0xFFUL;
+ unsigned long a3 = (laddr >> 8UL) & 0xFFUL;
+ unsigned long a4 = laddr & 0xFFUL;
+ sprintf(name, "%lu.%lu.%lu.%lu.in-addr.arpa", a4, a3, a2, a1);
}
else
{
@@ -99,13 +99,15 @@ void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa,
struct nameinfo_query *niquery;
unsigned int port = 0;
- /* Verify the buffer size */
- if (salen == sizeof(struct sockaddr_in))
+ /* Validate socket address family and length */
+ if ((sa->sa_family == AF_INET) &&
+ (salen == sizeof(struct sockaddr_in)))
{
addr = (struct sockaddr_in *)sa;
port = addr->sin_port;
}
- else if (salen == sizeof(struct sockaddr_in6))
+ else if ((sa->sa_family == AF_INET6) &&
+ (salen == sizeof(struct sockaddr_in6)))
{
addr6 = (struct sockaddr_in6 *)sa;
port = addr6->sin6_port;
@@ -232,7 +234,7 @@ static void nameinfo_callback(void *arg, int status, int timeouts,
char buf[255];
char *domain;
gethostname(buf, 255);
- if ((domain = strchr(buf, '.')))
+ if ((domain = strchr(buf, '.')) != NULL)
{
char *end = ares_striendstr(host->h_name, domain);
if (end)
@@ -243,6 +245,7 @@ static void nameinfo_callback(void *arg, int status, int timeouts,
niquery->callback(niquery->arg, ARES_SUCCESS, niquery->timeouts,
(char *)(host->h_name),
service);
+ free(niquery);
return;
}
/* We couldn't find the host, but it's OK, we can use the IP */
@@ -273,6 +276,7 @@ static void nameinfo_callback(void *arg, int status, int timeouts,
}
niquery->callback(niquery->arg, ARES_SUCCESS, niquery->timeouts, ipbuf,
service);
+ free(niquery);
return;
}
niquery->callback(niquery->arg, status, niquery->timeouts, NULL, NULL);
@@ -354,11 +358,11 @@ static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int flags,
#ifdef HAVE_IF_INDEXTONAME
int is_ll, is_mcll;
#endif
- char fmt_u[] = "%u";
- char fmt_lu[] = "%lu";
+ static const char fmt_u[] = "%u";
+ static const char fmt_lu[] = "%lu";
char tmpbuf[IF_NAMESIZE + 2];
size_t bufl;
- char *fmt = (sizeof(addr6->sin6_scope_id) > sizeof(unsigned int))?
+ const char *fmt = (sizeof(addr6->sin6_scope_id) > sizeof(unsigned int))?
fmt_lu:fmt_u;
tmpbuf[0] = '%';
@@ -406,8 +410,8 @@ static char *ares_striendstr(const char *s1, const char *s2)
c2 = s2;
while (c2 < s2+s2_len)
{
- lo1 = tolower(*c1);
- lo2 = tolower(*c2);
+ lo1 = TOLOWER(*c1);
+ lo2 = TOLOWER(*c2);
if (lo1 != lo2)
return NULL;
else
View
@@ -67,6 +67,7 @@
#include "ares.h"
#include "inet_net_pton.h"
#include "ares_library_init.h"
+#include "ares_nowarn.h"
#include "ares_private.h"
#ifdef ANDROID
@@ -94,7 +95,7 @@ static int init_id_key(rc4_key* key,int key_data_len);
#if !defined(WIN32) && !defined(WATT32)
static int sortlist_alloc(struct apattern **sortlist, int *nsort, struct apattern *pat);
-static int ip_addr(const char *s, int len, struct in_addr *addr);
+static int ip_addr(const char *s, ssize_t len, struct in_addr *addr);
static void natural_mask(struct apattern *pat);
static int config_domain(ares_channel channel, char *str);
static int config_lookup(ares_channel channel, const char *str,
@@ -129,8 +130,12 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
if (env)
curl_memdebug(env);
env = getenv("CARES_MEMLIMIT");
- if (env)
- curl_memlimit(atoi(env));
+ 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)
@@ -172,6 +177,10 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
channel->last_server = 0;
channel->last_timeout_processed = (time_t)now.tv_sec;
+ memset(&channel->local_dev_name, 0, sizeof(channel->local_dev_name));
+ channel->local_ip4 = 0;
+ memset(&channel->local_ip6, 0, sizeof(channel->local_ip6));
+
/* Initialize our lists of queries */
ares__init_list_head(&(channel->all_queries));
for (i = 0; i < ARES_QID_TABLE_SIZE; i++)
@@ -286,6 +295,10 @@ int ares_dup(ares_channel *dest, ares_channel src)
(*dest)->sock_create_cb = src->sock_create_cb;
(*dest)->sock_create_cb_data = src->sock_create_cb_data;
+ strncpy((*dest)->local_dev_name, src->local_dev_name, sizeof(src->local_dev_name));
+ (*dest)->local_ip4 = src->local_ip4;
+ memcpy((*dest)->local_ip6, src->local_ip6, sizeof(src->local_ip6));
+
/* Full name server cloning required when not all are IPv4 */
for (i = 0; i < src->nservers; i++)
{
@@ -393,10 +406,7 @@ int ares_save_options(ares_channel channel, struct ares_options *options,
if (!options->sortlist)
return ARES_ENOMEM;
for (i = 0; i < channel->nsort; i++)
- {
- memcpy(&(options->sortlist[i]), &(channel->sortlist[i]),
- sizeof(struct apattern));
- }
+ options->sortlist[i] = channel->sortlist[i];
}
options->nsort = channel->nsort;
@@ -490,18 +500,15 @@ static int init_by_options(ares_channel channel,
}
/* copy sortlist */
- if ((optmask & ARES_OPT_SORTLIST) && channel->nsort == -1)
- {
- channel->sortlist = malloc(options->nsort * sizeof(struct apattern));
- if (!channel->sortlist)
- return ARES_ENOMEM;
- for (i = 0; i < options->nsort; i++)
- {
- memcpy(&(channel->sortlist[i]), &(options->sortlist[i]),
- sizeof(struct apattern));
- }
- channel->nsort = options->nsort;
- }
+ if ((optmask & ARES_OPT_SORTLIST) && (channel->nsort == -1) &&
+ (options->nsort>0)) {
+ channel->sortlist = malloc(options->nsort * sizeof(struct apattern));
+ if (!channel->sortlist)
+ return ARES_ENOMEM;
+ for (i = 0; i < options->nsort; i++)
+ channel->sortlist[i] = options->sortlist[i];
+ channel->nsort = options->nsort;
+ }
channel->optmask = optmask;
@@ -1254,16 +1261,16 @@ static int config_sortlist(struct apattern **sortlist, int *nsort,
q = str;
while (*q && *q != '/' && *q != ';' && !ISSPACE(*q))
q++;
- memcpy(ipbuf, str, (int)(q-str));
- ipbuf[(int)(q-str)] = '\0';
+ memcpy(ipbuf, str, q-str);
+ ipbuf[q-str] = '\0';
/* Find the prefix */
if (*q == '/')
{
const char *str2 = q+1;
while (*q && *q != ';' && !ISSPACE(*q))
q++;
- memcpy(ipbufpfx, str, (int)(q-str));
- ipbufpfx[(int)(q-str)] = '\0';
+ memcpy(ipbufpfx, str, q-str);
+ ipbufpfx[q-str] = '\0';
str = str2;
}
else
@@ -1291,13 +1298,13 @@ static int config_sortlist(struct apattern **sortlist, int *nsort,
return ARES_ENOMEM;
}
/* See if it is just a regular IP */
- else if (ip_addr(ipbuf, (int)(q-str), &pat.addrV4) == 0)
+ else if (ip_addr(ipbuf, q-str, &pat.addrV4) == 0)
{
if (ipbufpfx[0])
{
- memcpy(ipbuf, str, (int)(q-str));
- ipbuf[(int)(q-str)] = '\0';
- if (ip_addr(ipbuf, (int)(q - str), &pat.mask.addr4) != 0)
+ memcpy(ipbuf, str, q-str);
+ ipbuf[q-str] = '\0';
+ if (ip_addr(ipbuf, q-str, &pat.mask.addr4) != 0)
natural_mask(&pat);
}
else
@@ -1394,13 +1401,13 @@ static int set_options(ares_channel channel, const char *str)
q++;
val = try_option(p, q, "ndots:");
if (val && channel->ndots == -1)
- channel->ndots = atoi(val);
+ channel->ndots = aresx_sltosi(strtol(val, NULL, 10));
val = try_option(p, q, "retrans:");
if (val && channel->timeout == -1)
- channel->timeout = atoi(val);
+ channel->timeout = aresx_sltosi(strtol(val, NULL, 10));
val = try_option(p, q, "retry:");
if (val && channel->tries == -1)
- channel->tries = atoi(val);
+ channel->tries = aresx_sltosi(strtol(val, NULL, 10));
val = try_option(p, q, "rotate");
if (val && channel->rotate == -1)
channel->rotate = 1;
@@ -1495,7 +1502,7 @@ static int sortlist_alloc(struct apattern **sortlist, int *nsort,
return 1;
}
-static int ip_addr(const char *ipbuf, int len, struct in_addr *addr)
+static int ip_addr(const char *ipbuf, ssize_t len, struct in_addr *addr)
{
/* Four octets and three periods yields at most 15 characters. */
@@ -1552,7 +1559,7 @@ static void randomize_key(unsigned char* key,int key_data_len)
#ifdef RANDOM_FILE
FILE *f = fopen(RANDOM_FILE, "rb");
if(f) {
- counter = fread(key, 1, key_data_len, f);
+ counter = aresx_uztosi(fread(key, 1, key_data_len, f));
fclose(f);
}
#endif
@@ -1604,6 +1611,28 @@ unsigned short ares__generate_new_id(rc4_key* key)
return r;
}
+void ares_set_local_ip4(ares_channel channel, unsigned int local_ip)
+{
+ channel->local_ip4 = local_ip;
+}
+
+/* local_ip6 should be 16 bytes in length */
+void ares_set_local_ip6(ares_channel channel,
+ const unsigned char* local_ip6)
+{
+ memcpy(&channel->local_ip6, local_ip6, sizeof(channel->local_ip6));
+}
+
+/* local_dev_name should be null terminated. */
+void ares_set_local_dev(ares_channel channel,
+ const char* local_dev_name)
+{
+ strncpy(channel->local_dev_name, local_dev_name,
+ sizeof(channel->local_dev_name));
+ channel->local_dev_name[sizeof(channel->local_dev_name) - 1] = 0;
+}
+
+
void ares_set_socket_callback(ares_channel channel,
ares_sock_create_callback cb,
void *data)
View
@@ -71,4 +71,8 @@ struct addrinfo
#endif
#endif
+/* Defined in ares_net_pton.c for no particular reason. */
+extern const struct ares_in6_addr ares_in6addr_any; /* :: */
+
+
#endif /* ARES_IPV6_H */
Oops, something went wrong.

0 comments on commit fc634cd

Please sign in to comment.