From 4e74385a1ae9eae4ae9e8d155dfd96978eb10e7a Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 3 Jan 2021 01:35:46 +0000 Subject: fix accessing an network address in a deleted context Both drop_connection and add_host_fail can drop the connection, which invalidates the context, and thus the address it contains. Thanks to wfaressuissia[m] for lots of help and prodding when debugging this --- src/cryptonote_protocol/cryptonote_protocol_handler.inl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/cryptonote_protocol') diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index bd39077ae..d6a08e21b 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -2835,12 +2835,15 @@ skip: epee::string_tools::to_string_hex(context.m_pruning_seed) << "), score " << score << ", flush_all_spans " << flush_all_spans); - if (score > 0) - m_p2p->add_host_fail(context.m_remote_address, score); - m_block_queue.flush_spans(context.m_connection_id, flush_all_spans); + // copy since dropping the connection will invalidate the context, and thus the address + const auto remote_address = context.m_remote_address; + m_p2p->drop_connection(context); + + if (score > 0) + m_p2p->add_host_fail(remote_address, score); } //------------------------------------------------------------------------------------------------------------------------ template -- cgit v1.2.3