[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r13130: add some missing checks for failing return values. (in tor/trunk: . src/or)



Author: nickm
Date: 2008-01-14 14:00:23 -0500 (Mon, 14 Jan 2008)
New Revision: 13130

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/circuitbuild.c
   tor/trunk/src/or/config.c
   tor/trunk/src/or/control.c
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/dns.c
   tor/trunk/src/or/dnsserv.c
   tor/trunk/src/or/eventdns.c
   tor/trunk/src/or/policies.c
Log:
 r17611@catbus:  nickm | 2008-01-14 13:44:16 -0500
 add some missing checks for failing return values.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r17611] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2008-01-14 19:00:19 UTC (rev 13129)
+++ tor/trunk/ChangeLog	2008-01-14 19:00:23 UTC (rev 13130)
@@ -44,6 +44,7 @@
       to check our fallback consensus.  Fixes bug 583.
     - Make bridges round geoip info up, not down.
     - Avoid a spurious free on base64 failure.  Bugfix on 0.1.2.
+    - Detect more kinds of possible internal error.
 
   o Minor features (controller):
     - Get NS events working again.  (Patch from tup)

Modified: tor/trunk/src/or/circuitbuild.c
===================================================================
--- tor/trunk/src/or/circuitbuild.c	2008-01-14 19:00:19 UTC (rev 13129)
+++ tor/trunk/src/or/circuitbuild.c	2008-01-14 19:00:23 UTC (rev 13130)
@@ -2617,7 +2617,7 @@
       }
       if (strlen(line->value) >= ISO_TIME_LEN+ISO_TIME_LEN+1) {
         /* ignore failure */
-        parse_iso_time(line->value+ISO_TIME_LEN+1, &last_try);
+        (void) parse_iso_time(line->value+ISO_TIME_LEN+1, &last_try);
       }
       if (!strcasecmp(line->key, "EntryGuardDownSince")) {
         node->unreachable_since = when;

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2008-01-14 19:00:19 UTC (rev 13129)
+++ tor/trunk/src/or/config.c	2008-01-14 19:00:23 UTC (rev 13130)
@@ -835,8 +835,12 @@
       "88.198.7.215:80 6833 3D07 61BC F397 A587 A0C0 B963 E4A9 E99E C4D3",
     NULL
   };
-  for (i=0; dirservers[i]; i++)
-    parse_dir_server_line(dirservers[i], type, 0);
+  for (i=0; dirservers[i]; i++) {
+    if (parse_dir_server_line(dirservers[i], type, 0)<0) {
+      log_err(LD_BUG, "Couldn't parse internal dirserver line %s",
+              dirservers[i]);
+    }
+  }
 }
 
 /** Look at all the config options for using alternate directory

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2008-01-14 19:00:19 UTC (rev 13129)
+++ tor/trunk/src/or/control.c	2008-01-14 19:00:23 UTC (rev 13130)
@@ -1500,9 +1500,9 @@
     question += strlen("extra-info/digest/");
     if (strlen(question) == HEX_DIGEST_LEN) {
       char d[DIGEST_LEN];
-      signed_descriptor_t *sd;
-      base16_decode(d, sizeof(d), question, strlen(question));
-      sd = extrainfo_get_by_descriptor_digest(d);
+      signed_descriptor_t *sd = NULL;
+      if (base16_decode(d, sizeof(d), question, strlen(question))==0)
+        sd = extrainfo_get_by_descriptor_digest(d);
       if (sd) {
         const char *body = signed_descriptor_get_body(sd);
         if (body)

Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2008-01-14 19:00:19 UTC (rev 13129)
+++ tor/trunk/src/or/directory.c	2008-01-14 19:00:23 UTC (rev 13130)
@@ -2959,7 +2959,11 @@
   {
     char digest[DIGEST_LEN];
     trusted_dir_server_t *dir;
-    base16_decode(digest, DIGEST_LEN, fp, strlen(fp));
+    if (base16_decode(digest, DIGEST_LEN, fp, strlen(fp))<0) {
+      log_warn(LD_BUG, "Called with bad fingerprint in list: %s",
+               escaped(fp));
+      continue;
+    }
     dir = router_get_trusteddirserver_by_digest(digest);
 
     if (dir)
@@ -3070,7 +3074,11 @@
       tor_assert(!was_extrainfo); /* not supported yet */
       SMARTLIST_FOREACH(failed, const char *, cp,
       {
-        base16_decode(digest, DIGEST_LEN, cp, strlen(cp));
+        if (base16_decode(digest, DIGEST_LEN, cp, strlen(cp))<0) {
+          log_warn(LD_BUG, "Malformed fingerprint in list: %s",
+                   escaped(cp));
+          continue;
+        }
         retry_bridge_descriptor_fetch_directly(digest);
       });
     }
@@ -3079,7 +3087,10 @@
   SMARTLIST_FOREACH(failed, const char *, cp,
   {
     download_status_t *dls = NULL;
-    base16_decode(digest, DIGEST_LEN, cp, strlen(cp));
+    if (base16_decode(digest, DIGEST_LEN, cp, strlen(cp)) < 0) {
+      log_warn(LD_BUG, "Malformed fingerprint in list: %s", escaped(cp));
+      continue;
+    }
     if (was_extrainfo) {
       signed_descriptor_t *sd =
         router_get_by_extrainfo_digest(digest);

Modified: tor/trunk/src/or/dns.c
===================================================================
--- tor/trunk/src/or/dns.c	2008-01-14 19:00:19 UTC (rev 13129)
+++ tor/trunk/src/or/dns.c	2008-01-14 19:00:23 UTC (rev 13130)
@@ -1458,8 +1458,11 @@
     return;
   SMARTLIST_FOREACH(options->ServerDNSTestAddresses, const char *, address,
     {
-      evdns_resolve_ipv4(address, DNS_QUERY_NO_SEARCH, evdns_callback,
-                         tor_strdup(address));
+      int r = evdns_resolve_ipv4(address, DNS_QUERY_NO_SEARCH, evdns_callback,
+                                 tor_strdup(address));
+      if (r)
+        log_info(LD_EXIT, "eventdns rejected test address %s: error %d",
+                 escaped_safe_str(address), r);
     });
 }
 
@@ -1512,7 +1515,9 @@
   evtimer_set(&launch_event, launch_test_addresses, NULL);
   timeout.tv_sec = 30;
   timeout.tv_usec = 0;
-  evtimer_add(&launch_event, &timeout);
+  if (evtimer_add(&launch_event, &timeout)<0) {
+    log_warn(LD_BUG, "Couldn't add timer for checking for dns hijacking");
+  }
 }
 
 /** Return true iff our DNS servers lie to us too much to be trustd. */

Modified: tor/trunk/src/or/dnsserv.c
===================================================================
--- tor/trunk/src/or/dnsserv.c	2008-01-14 19:00:19 UTC (rev 13129)
+++ tor/trunk/src/or/dnsserv.c	2008-01-14 19:00:23 UTC (rev 13130)
@@ -130,7 +130,12 @@
 
   conn->dns_server_request = req;
 
-  connection_add(TO_CONN(conn));
+  if (connection_add(TO_CONN(conn)) < 0) {
+    log_warn(LD_APP, "Couldn't register dummy connection for DNS request");
+    evdns_server_request_respond(req, DNS_ERR_SERVERFAILED);
+    connection_free(TO_CONN(conn));
+    return;
+  }
 
   control_event_stream_status(conn, STREAM_EVENT_NEW, 0);
 
@@ -171,7 +176,12 @@
   strlcpy(conn->socks_request->address, name,
           sizeof(conn->socks_request->address));
 
-  connection_add(TO_CONN(conn));
+  if (connection_add(TO_CONN(conn))<0) {
+    log_warn(LD_APP, "Couldn't register dummy connection for RESOLVE request");
+    evdns_server_request_respond(req, DNS_ERR_SERVERFAILED);
+    connection_free(TO_CONN(conn));
+    return;
+  }
 
   /* Now, throw the connection over to get rewritten (which will answer it
   * immediately if it's in the cache, or completely bogus, or automapped),

Modified: tor/trunk/src/or/eventdns.c
===================================================================
--- tor/trunk/src/or/eventdns.c	2008-01-14 19:00:19 UTC (rev 13129)
+++ tor/trunk/src/or/eventdns.c	2008-01-14 19:00:23 UTC (rev 13130)
@@ -1462,7 +1462,10 @@
 
 	event_set(&port->event, port->socket, EV_READ | EV_PERSIST,
 			  server_port_ready_callback, port);
-	event_add(&port->event, NULL); /* check return. */
+	if (event_add(&port->event, NULL)<0) {
+		free(port);
+		return NULL;
+	}
 	return port;
 }
 

Modified: tor/trunk/src/or/policies.c
===================================================================
--- tor/trunk/src/or/policies.c	2008-01-14 19:00:19 UTC (rev 13129)
+++ tor/trunk/src/or/policies.c	2008-01-14 19:00:23 UTC (rev 13130)
@@ -332,11 +332,12 @@
 load_policy_from_option(config_line_t *config, smartlist_t **policy,
                         int assume_action)
 {
+  int r;
   addr_policy_list_free(*policy);
   *policy = NULL;
-  parse_addr_policy(config, policy, assume_action);
-  if (!*policy)
-    return;
+  r = parse_addr_policy(config, policy, assume_action);
+  if (r < 0 || !*policy)
+    return; /* XXXX020 have an error return. */
   SMARTLIST_FOREACH(*policy, addr_policy_t *, n, {
       /* ports aren't used. */
       n->prt_min = 1;
@@ -598,7 +599,9 @@
   tmp.key = NULL;
   tmp.value = (char*) more;
   tmp.next = NULL;
-  parse_addr_policy(&tmp, policy, -1);
+  if (parse_addr_policy(&tmp, policy, -1)<0) {
+    log_warn(LD_BUG, "Unable to parse internally generated policy %s",more);
+  }
 }
 
 /** Detect and excise "dead code" from the policy *<b>dest</b>. */