From 5858598604c511ff57a434196d27acf2f49cf23f Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 11 Apr 2019 21:57:51 +0000 Subject: p2p: fix integer overflow in host bans --- tests/unit_tests/ban.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'tests/unit_tests') diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/ban.cpp index eb1ee8932..c8ce19ba4 100644 --- a/tests/unit_tests/ban.cpp +++ b/tests/unit_tests/ban.cpp @@ -93,18 +93,7 @@ typedef nodetool::node_server hosts = server.get_blocked_hosts(); - for (auto rec: hosts) - { - if (rec.first == host) - { - if (t) - *t = rec.second; - return true; - } - } - return false; + return server.is_host_blocked(address.host_str(), t); } TEST(ban, add) @@ -192,5 +181,21 @@ TEST(ban, add) ASSERT_TRUE(t >= 4); } +TEST(ban, limit) +{ + test_core pr_core; + cryptonote::t_cryptonote_protocol_handler cprotocol(pr_core, NULL); + Server server(cprotocol); + cprotocol.set_p2p_endpoint(&server); + + // starts empty + ASSERT_TRUE(server.get_blocked_hosts().empty()); + ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4))); + ASSERT_TRUE(server.block_host(MAKE_IPV4_ADDRESS(1,2,3,4), std::numeric_limits::max() - 1)); + ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4))); + ASSERT_TRUE(server.block_host(MAKE_IPV4_ADDRESS(1,2,3,4), 1)); + ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4))); +} + namespace nodetool { template class node_server>; } namespace cryptonote { template class t_cryptonote_protocol_handler; } -- cgit v1.2.3