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
This commit is contained in:
moneromooo-monero 2021-01-03 01:35:46 +00:00
parent 16c780d568
commit 4e74385a1a
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
2 changed files with 15 additions and 9 deletions

View file

@ -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<class t_core>