[or-cvs] [tor/release-0.2.2] Merge branch 'bug2328_021' into maint-0.2.1

arma at torproject.org arma at torproject.org
Sat Jan 15 22:31:48 UTC 2011


commit d6b49c55c58777ec7457cd8ae6a372fe0939f920
Merge: e432068 2008728
Author: Nick Mathewson <nickm at torproject.org>
Date:   Thu Jan 6 13:36:29 2011 -0500

    Merge branch 'bug2328_021' into maint-0.2.1

 changes/bug2328          |    8 ++++++++
 src/or/connection_edge.c |   30 +++++++++++++++++++++++++-----
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --combined src/or/connection_edge.c
index 5e74ad6,001408a..4caa01c
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@@ -1,7 -1,7 +1,7 @@@
  /* Copyright (c) 2001 Matej Pfajfar.
   * Copyright (c) 2001-2004, Roger Dingledine.
   * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
 - * Copyright (c) 2007-2010, The Tor Project, Inc. */
 + * Copyright (c) 2007-2011, The Tor Project, Inc. */
  /* See LICENSE for licensing information */
  
  /**
@@@ -1142,6 -1142,8 +1142,8 @@@ address_is_in_virtual_range(const char 
  /** Return a newly allocated string holding an address of <b>type</b>
   * (one of RESOLVED_TYPE_{IPV4|HOSTNAME}) that has not yet been mapped,
   * and that is very unlikely to be the address of any real host.
+  *
+  * May return NULL if we have run out of virtual addresses.
   */
  static char *
  addressmap_get_virtual_address(int type)
@@@ -1167,6 -1169,10 +1169,10 @@@
        while ((next_virtual_addr & 0xff) == 0 ||
               (next_virtual_addr & 0xff) == 0xff) {
          ++next_virtual_addr;
+         if (! --available) {
+           log_warn(LD_CONFIG, "Ran out of virtual addresses!");
+           return NULL;
+         }
        }
        in.s_addr = htonl(next_virtual_addr);
        tor_inet_ntoa(&in, buf, sizeof(buf));
@@@ -1178,7 -1184,7 +1184,7 @@@
        ++next_virtual_addr;
        --available;
        log_info(LD_CONFIG, "%d addrs available", (int)available);
-       if (! --available) {
+       if (! available) {
          log_warn(LD_CONFIG, "Ran out of virtual addresses!");
          return NULL;
        }
@@@ -1199,14 -1205,15 +1205,15 @@@
   * allocated string.  If another address of the same type is already
   * mapped to <b>new_address</b>, try to return a copy of that address.
   *
-  * The string in <b>new_address</b> may be freed, or inserted into a map
-  * as appropriate.
+  * The string in <b>new_address</b> may be freed or inserted into a map
+  * as appropriate.  May return NULL if are out of virtual addresses.
   **/
  const char *
  addressmap_register_virtual_address(int type, char *new_address)
  {
    char **addrp;
    virtaddress_entry_t *vent;
+   int vent_needs_to_be_added = 0;
  
    tor_assert(new_address);
    tor_assert(addressmap);
@@@ -1215,7 -1222,7 +1222,7 @@@
    vent = strmap_get(virtaddress_reversemap, new_address);
    if (!vent) {
      vent = tor_malloc_zero(sizeof(virtaddress_entry_t));
-     strmap_set(virtaddress_reversemap, new_address, vent);
+     vent_needs_to_be_added = 1;
    }
  
    addrp = (type == RESOLVED_TYPE_IPV4) ?
@@@ -1225,6 -1232,7 +1232,7 @@@
      if (ent && ent->new_address &&
          !strcasecmp(new_address, ent->new_address)) {
        tor_free(new_address);
+       tor_assert(!vent_needs_to_be_added);
        return tor_strdup(*addrp);
      } else
        log_warn(LD_BUG,
@@@ -1236,7 -1244,14 +1244,14 @@@
  
    tor_free(*addrp);
    *addrp = addressmap_get_virtual_address(type);
+   if (!*addrp) {
+     tor_free(vent);
+     tor_free(new_address);
+     return NULL;
+   }
    log_info(LD_APP, "Registering map from %s to %s", *addrp, new_address);
+   if (vent_needs_to_be_added)
+     strmap_set(virtaddress_reversemap, new_address, vent);
    addressmap_register(*addrp, new_address, 2, ADDRMAPSRC_CONTROLLER);
  
  #if 0
@@@ -1415,7 -1430,12 +1430,12 @@@ connection_ap_handshake_rewrite_and_att
        const char *new_addr;
        new_addr = addressmap_register_virtual_address(
                                RESOLVED_TYPE_IPV4, tor_strdup(socks->address));
-       tor_assert(new_addr);
+       if (! new_addr) {
+         log_warn(LD_APP, "Unable to automap address %s",
+                  escaped_safe_str(socks->address));
+         connection_mark_unattached_ap(conn, END_STREAM_REASON_INTERNAL);
+         return -1;
+       }
        log_info(LD_APP, "Automapping %s to %s",
                 escaped_safe_str(socks->address), safe_str(new_addr));
        strlcpy(socks->address, new_addr, sizeof(socks->address));





More information about the tor-commits mailing list