File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,25 @@ namespace {
1212static std::unique_ptr<const CChainParams> g_main_params{nullptr };
1313static const CService empty_service{CService ()};
1414
15+ static constexpr std::string_view SAFE_CHARS_IPPORT{" 1234567890.[]:" };
16+
1517const bool IsNodeOnMainnet () { return Params ().NetworkIDString () == CBaseChainParams::MAIN; }
1618const CChainParams& MainParams ()
1719{
1820 // TODO: use real args here
1921 if (!g_main_params) g_main_params = CreateChainParams (ArgsManager{}, CBaseChainParams::MAIN);
2022 return *g_main_params;
2123}
24+
25+ bool MatchCharsFilter (const std::string& input, const std::string_view& filter)
26+ {
27+ for (char c : input) {
28+ if (filter.find (c) == std::string::npos) {
29+ return false ;
30+ }
31+ }
32+ return true ;
33+ }
2234} // anonymous namespace
2335
2436bool NetInfoEntry::operator ==(const NetInfoEntry& rhs) const
@@ -138,6 +150,10 @@ NetInfoStatus MnNetInfo::AddEntry(const std::string& input)
138150 if (!IsEmpty ()) {
139151 return NetInfoStatus::MaxLimit;
140152 }
153+ // Contains invalid characters, unlikely to pass Lookup(), fast-fail
154+ if (!MatchCharsFilter (input, SAFE_CHARS_IPPORT)) {
155+ return NetInfoStatus::BadInput;
156+ }
141157 if (auto service = Lookup (input, /* portDefault=*/ Params ().GetDefaultPort (), /* fAllowLookup=*/ false ); service.has_value ()) {
142158 const auto ret = ValidateService (service.value ());
143159 if (ret == NetInfoStatus::Success) {
You can’t perform that action at this time.
0 commit comments