From 571974d02a1dde932336e459b3791ad63131a587 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 7 Aug 2008 20:19:53 +0000 Subject: Backport to 0.1.2.x: Never allow a circuit to be created with the same circid as a circuit that has been marked for close. May fix 779. Needs testing. svn:r16464 --- ChangeLog | 3 +++ src/or/circuitbuild.c | 2 +- src/or/circuitlist.c | 8 ++++++++ src/or/command.c | 2 +- src/or/or.h | 1 + 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8177fac0a9..218b0d729d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,9 @@ Changes in version 0.1.2.20 - 2008-??-?? would stop building circuits and start refusing connections after 24 hours, since we falsely believed that Tor was dormant. Reported by nwf. + - Ensure that two circuits can never exist on the same connection + with the same circuit ID, even if one is marked for close. This + is conceivably a bugfix for bug 779; fixes a bug on 0.1.0.4-rc. o Minor bugfixes: - Stop recommending that every server operator send mail to tor-ops. diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c index 2e1a79b7fe..3fd80d6bfc 100644 --- a/src/or/circuitbuild.c +++ b/src/or/circuitbuild.c @@ -94,7 +94,7 @@ get_unique_circ_id_by_conn(or_connection_t *conn) return 0; } test_circ_id |= high_bit; - } while (circuit_get_by_circid_orconn(test_circ_id, conn)); + } while (circuit_id_in_use_on_orconn(test_circ_id, conn)); return test_circ_id; } diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c index 47e6d6a25a..cbb7bcc9ad 100644 --- a/src/or/circuitlist.c +++ b/src/or/circuitlist.c @@ -615,6 +615,14 @@ circuit_get_by_circid_orconn(uint16_t circ_id, or_connection_t *conn) return circ; } +/** Return true iff the circuit ID circ_id is currently used by a + * circuit, marked or not, on conn. */ +int +circuit_id_in_use_on_orconn(uint16_t circ_id, or_connection_t *conn) +{ + return circuit_get_by_circid_orconn_impl(circ_id, conn) != NULL; +} + /** Return the circuit that a given edge connection is using. */ circuit_t * circuit_get_by_edge_conn(edge_connection_t *conn) diff --git a/src/or/command.c b/src/or/command.c index 208df8b22f..aef550e396 100644 --- a/src/or/command.c +++ b/src/or/command.c @@ -196,7 +196,7 @@ command_process_create_cell(cell_t *cell, or_connection_t *conn) return; } - if (circuit_get_by_circid_orconn(cell->circ_id, conn)) { + if (circuit_id_in_use_on_orconn(cell->circ_id, conn)) { routerinfo_t *router = router_get_by_digest(conn->identity_digest); log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, "Received CREATE cell (circID %d) for known circ. " diff --git a/src/or/or.h b/src/or/or.h index 6fd403c64f..d83392ce96 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1997,6 +1997,7 @@ origin_circuit_t *origin_circuit_new(void); or_circuit_t *or_circuit_new(uint16_t p_circ_id, or_connection_t *p_conn); circuit_t *circuit_get_by_circid_orconn(uint16_t circ_id, or_connection_t *conn); +int circuit_id_in_use_on_orconn(uint16_t circ_id, or_connection_t *conn); circuit_t *circuit_get_by_edge_conn(edge_connection_t *conn); void circuit_unlink_all_from_or_conn(or_connection_t *conn, int reason); origin_circuit_t *circuit_get_by_global_id(uint32_t id); -- cgit v1.2.3-54-g00ecf