Skip to content

Commit e0c63ab

Browse files
committed
evo: prohibit overwriting entry in MnNetInfo
1 parent 9a8e485 commit e0c63ab

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

src/evo/deterministicmns.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,7 @@ static bool CheckService(const ProTx& proTx, TxValidationState& state)
12511251
return true;
12521252
// Shouldn't be possible during self-checks
12531253
case NetInfoStatus::BadInput:
1254+
case NetInfoStatus::MaxLimit:
12541255
ASSERT_IF_DEBUG(false);
12551256
} // no default case, so the compiler can warn about missing cases
12561257
assert(false);

src/evo/netinfo.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ NetInfoStatus MnNetInfo::ValidateService(const CService& service)
159159

160160
NetInfoStatus MnNetInfo::AddEntry(const std::string& input)
161161
{
162+
if (!IsEmpty()) {
163+
return NetInfoStatus::MaxLimit;
164+
}
162165
if (auto service = Lookup(input, /*portDefault=*/Params().GetDefaultPort(), /*fAllowLookup=*/false);
163166
service.has_value()) {
164167
const auto ret = ValidateService(service.value());

src/evo/netinfo.h

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class CService;
1616
enum class NetInfoStatus : uint8_t {
1717
// Managing entries
1818
BadInput,
19+
MaxLimit,
1920

2021
// Validation
2122
BadAddress,
@@ -42,6 +43,8 @@ constexpr std::string_view NISToString(const NetInfoStatus code)
4243
return "unroutable address";
4344
case NetInfoStatus::Malformed:
4445
return "malformed";
46+
case NetInfoStatus::MaxLimit:
47+
return "too many entries";
4548
case NetInfoStatus::Success:
4649
return "success";
4750
} // no default case, so the compiler can warn about missing cases

src/test/evo_netinfo_tests.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ BOOST_AUTO_TEST_CASE(mnnetinfo_rules)
5959
ValidateGetEntries(netInfo.GetEntries(), /*expected_size=*/1);
6060
}
6161
}
62+
63+
{
64+
// MnNetInfo only stores one value, overwriting prohibited
65+
MnNetInfo netInfo;
66+
BOOST_CHECK_EQUAL(netInfo.AddEntry("1.1.1.1:9999"), NetInfoStatus::Success);
67+
BOOST_CHECK_EQUAL(netInfo.AddEntry("1.1.1.2:9999"), NetInfoStatus::MaxLimit);
68+
ValidateGetEntries(netInfo.GetEntries(), /*expected_size=*/1);
69+
}
6270
}
6371

6472
bool CheckIfSerSame(const CService& lhs, const MnNetInfo& rhs)

0 commit comments

Comments
 (0)