diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-02-07 10:38:05 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-02-07 10:38:05 -0500 |
commit | 8a1f0876ed329f6c9d73e6ca786cd8437e6bb55b (patch) | |
tree | 3300d327a1143fc86b9a6286b00cff8883c9e08c /src/or | |
parent | 3f5a710958bfa2e6d1c2a6d78b0718514f2f7350 (diff) | |
parent | f2a30413a35bb360323a98fb124fbc629245978d (diff) | |
download | tor-8a1f0876ed329f6c9d73e6ca786cd8437e6bb55b.tar.gz tor-8a1f0876ed329f6c9d73e6ca786cd8437e6bb55b.zip |
Merge branch 'maint-0.2.6' into maint-0.2.7-redux
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/dnsserv.c | 4 | ||||
-rw-r--r-- | src/or/main.c | 55 |
2 files changed, 52 insertions, 7 deletions
diff --git a/src/or/dnsserv.c b/src/or/dnsserv.c index f7710908bd..f3618cc2c5 100644 --- a/src/or/dnsserv.c +++ b/src/or/dnsserv.c @@ -87,8 +87,6 @@ evdns_server_callback(struct evdns_server_request *req, void *data_) for (i = 0; i < req->nquestions; ++i) { if (req->questions[i]->dns_question_class != EVDNS_CLASS_INET) continue; - if (! q) - q = req->questions[i]; switch (req->questions[i]->type) { case EVDNS_TYPE_A: case EVDNS_TYPE_AAAA: @@ -96,7 +94,7 @@ evdns_server_callback(struct evdns_server_request *req, void *data_) /* We always pick the first one of these questions, if there is one. */ if (! supported_q) - supported_q = q; + supported_q = req->questions[i]; break; default: break; diff --git a/src/or/main.c b/src/or/main.c index 9b3dbb5586..035686df9c 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -567,6 +567,45 @@ connection_is_reading(connection_t *conn) (conn->read_event && event_pending(conn->read_event, EV_READ, NULL)); } +/** Check whether <b>conn</b> is correct in having (or not having) a + * read/write event (passed in <b>ev</b). On success, return 0. On failure, + * log a warning and return -1. */ +static int +connection_check_event(connection_t *conn, struct event *ev) +{ + int bad; + + if (conn->type == CONN_TYPE_AP && TO_EDGE_CONN(conn)->is_dns_request) { + /* DNS requests which we launch through the dnsserv.c module do not have + * any underlying socket or any underlying linked connection, so they + * shouldn't have any attached events either. + */ + bad = ev != NULL; + } else { + /* Everytyhing else should have an underlying socket, or a linked + * connection (which is also tracked with a read_event/write_event pair). + */ + bad = ev == NULL; + } + + if (bad) { + log_warn(LD_BUG, "Event missing on connection %p [%s;%s]. " + "socket=%d. linked=%d. " + "is_dns_request=%d. Marked_for_close=%s:%d", + conn, + conn_type_to_string(conn->type), + conn_state_to_string(conn->type, conn->state), + (int)conn->s, (int)conn->linked, + (conn->type == CONN_TYPE_AP && TO_EDGE_CONN(conn)->is_dns_request), + conn->marked_for_close_file ? conn->marked_for_close_file : "-", + conn->marked_for_close + ); + //log_backtrace(LOG_WARN, LD_BUG, "Backtrace attached."); + return -1; + } + return 0; +} + /** Tell the main loop to stop notifying <b>conn</b> of any read events. */ MOCK_IMPL(void, connection_stop_reading,(connection_t *conn)) @@ -578,7 +617,9 @@ connection_stop_reading,(connection_t *conn)) return; }); - tor_assert(conn->read_event); + if (connection_check_event(conn, conn->read_event) < 0) { + return; + } if (conn->linked) { conn->reading_from_linked_conn = 0; @@ -603,7 +644,9 @@ connection_start_reading,(connection_t *conn)) return; }); - tor_assert(conn->read_event); + if (connection_check_event(conn, conn->read_event) < 0) { + return; + } if (conn->linked) { conn->reading_from_linked_conn = 1; @@ -643,7 +686,9 @@ connection_stop_writing,(connection_t *conn)) return; }); - tor_assert(conn->write_event); + if (connection_check_event(conn, conn->write_event) < 0) { + return; + } if (conn->linked) { conn->writing_to_linked_conn = 0; @@ -669,7 +714,9 @@ connection_start_writing,(connection_t *conn)) return; }); - tor_assert(conn->write_event); + if (connection_check_event(conn, conn->write_event) < 0) { + return; + } if (conn->linked) { conn->writing_to_linked_conn = 1; |