Skip to content

Commit 88b69c4

Browse files
committed
evo: prohibit overwriting entry in MnNetInfo
1 parent 4d878eb commit 88b69c4

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

src/evo/deterministicmns.cpp

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

src/evo/netinfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ NetInfoStatus MnNetInfo::ValidateService(const CService& service)
171171

172172
NetInfoStatus MnNetInfo::AddEntry(const std::string& input)
173173
{
174+
if (!IsEmpty()) {
175+
return NetInfoStatus::MaxLimit;
176+
}
174177
if (auto service = Lookup(input, /*portDefault=*/Params().GetDefaultPort(), /*fAllowLookup=*/false);
175178
service.has_value()) {
176179
const auto ret = ValidateService(service.value());

src/evo/netinfo.h

Lines changed: 3 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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)