cURL / Mailing Lists / curl-library / Single Mail

curl-library

[PATCH] ares: Fix some crashes when NULLs are sent to c-ares.

From: <greearb_at_candelatech.com>
Date: Wed, 6 Mar 2013 17:11:18 -0800

From: Ben Greear <greearb_at_candelatech.com>

Generally, treat NULL as empty string or other zero
value configuration.

Signed-off-by: Ben Greear <greearb_at_candelatech.com>

---
 ares_init.c    | 16 ++++++++++++----
 ares_options.c |  5 +++--
 2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/ares_init.c b/ares_init.c
index d23c1b0..e3f9e5a 100644
--- a/ares_init.c
+++ b/ares_init.c
@@ -1952,16 +1952,24 @@ void ares_set_local_ip4(ares_channel channel, unsigned int local_ip)
 void ares_set_local_ip6(ares_channel channel,
                         const unsigned char* local_ip6)
 {
-  memcpy(&channel->local_ip6, local_ip6, sizeof(channel->local_ip6));
+  if(local_ip6)
+    memcpy(&channel->local_ip6, local_ip6, sizeof(channel->local_ip6));
+  else
+    memset(&channel->local_ip6, 0, 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;
+  if(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;
+  }
+  else {
+    channel->local_dev_name[0] = 0;
+  }
 }
 
 
diff --git a/ares_options.c b/ares_options.c
index 5466cb2..9abd27e 100644
--- a/ares_options.c
+++ b/ares_options.c
@@ -135,7 +135,7 @@ int ares_set_servers(ares_channel channel,
 int ares_set_servers_csv(ares_channel channel,
                          const char* _csv)
 {
-  size_t i;
+  size_t i = 0;
   char* csv = NULL;
   char* ptr;
   char* start_host;
@@ -151,7 +151,8 @@ int ares_set_servers_csv(ares_channel channel,
 
   ares__destroy_servers_state(channel);
 
-  i = strlen(_csv);
+  if (_csv)
+    i = strlen(_csv);
   if (i == 0)
      return ARES_SUCCESS; /* blank all servers */
 
-- 
1.7.11.7
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2013-03-07