diff options
author | George Kadianakis <desnacked@riseup.net> | 2017-08-03 15:47:06 +0300 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-08-08 20:29:34 -0400 |
commit | 7c507a1f7f58adb48be887cd26686190c3b22cfd (patch) | |
tree | eac4b2d44a35f6e4065c5921c609f2669f924be4 | |
parent | e42c55626abf7447a154f5271e3bc35743340a21 (diff) | |
download | tor-7c507a1f7f58adb48be887cd26686190c3b22cfd.tar.gz tor-7c507a1f7f58adb48be887cd26686190c3b22cfd.zip |
Relax assertions: turn them to BUGs and non-fatal asserts.
-rw-r--r-- | src/or/connection_edge.c | 4 | ||||
-rw-r--r-- | src/or/hs_service.c | 33 | ||||
-rw-r--r-- | src/or/hs_service.h | 4 | ||||
-rw-r--r-- | src/test/test_hs_service.c | 2 |
4 files changed, 30 insertions, 13 deletions
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 41e5f88ab8..9f0cc061e1 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -3098,10 +3098,12 @@ handle_hs_exit_conn(circuit_t *circ, edge_connection_t *conn) /* Setup the identifier to be the one for the circuit service. */ conn->hs_ident = hs_ident_edge_conn_new(&origin_circ->hs_ident->identity_pk); + tor_assert(connection_edge_is_rendezvous_stream(conn)); ret = hs_service_set_conn_addr_port(origin_circ, conn); } else { /* We should never get here if the circuit's purpose is rendezvous. */ - tor_assert(0); + tor_assert_nonfatal_unreached(); + return -1; } if (ret < 0) { log_info(LD_REND, "Didn't find rendezvous service (addr%s, port %d)", diff --git a/src/or/hs_service.c b/src/or/hs_service.c index 30f693108b..22739334dd 100644 --- a/src/or/hs_service.c +++ b/src/or/hs_service.c @@ -377,12 +377,16 @@ service_intro_point_new(const extend_info_t *ei, unsigned int is_legacy) * mandatory. */ ls = hs_desc_link_specifier_new(ei, LS_IPV4); /* It is impossible to have an extend info object without a v4. */ - tor_assert(ls); + if (BUG(!ls)) { + goto err; + } smartlist_add(ip->base.link_specifiers, ls); ls = hs_desc_link_specifier_new(ei, LS_LEGACY_ID); /* It is impossible to have an extend info object without an identity * digest. */ - tor_assert(ls); + if (BUG(!ls)) { + goto err; + } smartlist_add(ip->base.link_specifiers, ls); ls = hs_desc_link_specifier_new(ei, LS_ED25519_ID); /* It is impossible to have an extend info object without an ed25519 @@ -546,8 +550,9 @@ get_node_from_intro_point(const hs_service_intro_point_t *ip) tor_assert(ip); ls = get_link_spec_by_type(ip, LS_LEGACY_ID); - /* Legacy ID is mandatory for an intro point object to have. */ - tor_assert(ls); + if (BUG(!ls)) { + return NULL; + } /* XXX In the future, we want to only use the ed25519 ID (#22173). */ return node_get_by_id((const char *) ls->u.legacy_id); } @@ -1427,7 +1432,10 @@ pick_needed_intro_points(hs_service_t *service, * robin so they are considered valid nodes to pick again. */ DIGEST256MAP_FOREACH(desc->intro_points.map, key, hs_service_intro_point_t *, ip) { - smartlist_add(exclude_nodes, (void *) get_node_from_intro_point(ip)); + const node_t *intro_node = get_node_from_intro_point(ip); + if (intro_node) { + smartlist_add(exclude_nodes, (void*)intro_node); + } } DIGEST256MAP_FOREACH_END; /* Also, add the failing intro points that our descriptor encounteered in * the exclude node list. */ @@ -2299,10 +2307,17 @@ service_intro_circ_has_opened(origin_circuit_t *circ) hs_service_descriptor_t *desc = NULL; tor_assert(circ); - tor_assert(circ->cpath); - /* Getting here means this is a v3 intro circuit. */ - tor_assert(circ->hs_ident); - tor_assert(TO_CIRCUIT(circ)->purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO); + + /* Let's do some basic sanity checking of the circ state */ + if (BUG(!circ->cpath)) { + return; + } + if (BUG(TO_CIRCUIT(circ)->purpose != CIRCUIT_PURPOSE_S_ESTABLISH_INTRO)) { + return; + } + if (BUG(!circ->hs_ident)) { + return; + } /* Get the corresponding service and intro point. */ get_objects_from_ident(circ->hs_ident, &service, &ip, &desc); diff --git a/src/or/hs_service.h b/src/or/hs_service.h index cb2a7aa80e..cf2e1fa6f4 100644 --- a/src/or/hs_service.h +++ b/src/or/hs_service.h @@ -313,8 +313,8 @@ STATIC void get_objects_from_ident(const hs_ident_circuit_t *ident, hs_service_t **service, hs_service_intro_point_t **ip, hs_service_descriptor_t **desc); -STATIC const node_t *get_node_from_intro_point( - const hs_service_intro_point_t *ip); +STATIC const node_t * +get_node_from_intro_point(const hs_service_intro_point_t *ip); STATIC int can_service_launch_intro_circuit(hs_service_t *service, time_t now); STATIC int intro_point_should_expire(const hs_service_intro_point_t *ip, diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c index 6d5ea7ed7d..2ad8393e84 100644 --- a/src/test/test_hs_service.c +++ b/src/test/test_hs_service.c @@ -540,7 +540,7 @@ test_helper_functions(void *arg) /* Testing get_node_from_intro_point() */ { const node_t *node = get_node_from_intro_point(ip); - tt_assert(node == &mock_node); + tt_ptr_op(node, OP_EQ, &mock_node); SMARTLIST_FOREACH_BEGIN(ip->base.link_specifiers, hs_desc_link_specifier_t *, ls) { if (ls->type == LS_LEGACY_ID) { |