aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-01-06 13:38:08 -0500
committerNick Mathewson <nickm@torproject.org>2011-01-06 13:38:08 -0500
commitd4b265d692aeb00cb862b7098f35e3de88055ff7 (patch)
treeb3e8e6c0f974fb375256d5dea4fe3beabe6fd6d7 /src
parentfd8f7991e47d02cc345af6f190a7b480703822df (diff)
parentd6329eda96e88ebe7211204b0cc34340f14ce938 (diff)
downloadtor-d4b265d692aeb00cb862b7098f35e3de88055ff7.tar
tor-d4b265d692aeb00cb862b7098f35e3de88055ff7.tar.gz
Merge remote branch 'origin/maint-0.2.2'
Diffstat (limited to 'src')
-rw-r--r--src/or/connection_edge.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 53abaddd3..8bfc8b464 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -1180,6 +1180,8 @@ address_is_in_virtual_range(const char *address)
/** 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)
@@ -1204,6 +1206,10 @@ addressmap_get_virtual_address(int type)
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;
+ }
}
if (!strmap_get(addressmap, fmt_addr32(next_virtual_addr))) {
++next_virtual_addr;
@@ -1213,7 +1219,7 @@ addressmap_get_virtual_address(int type)
++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;
}
@@ -1234,14 +1240,15 @@ addressmap_get_virtual_address(int type)
* 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);
@@ -1250,7 +1257,7 @@ addressmap_register_virtual_address(int type, char *new_address)
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) ?
@@ -1260,6 +1267,7 @@ addressmap_register_virtual_address(int type, char *new_address)
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,
@@ -1273,7 +1281,14 @@ addressmap_register_virtual_address(int type, char *new_address)
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
@@ -1473,7 +1488,12 @@ connection_ap_handshake_rewrite_and_attach(edge_connection_t *conn,
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_client(socks->address),
safe_str_client(new_addr));