aboutsummaryrefslogtreecommitdiff
path: root/src/net_types.cpp
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-06-28 16:41:11 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-12-14 18:58:45 +0100
commitfaa6c3d44c861c0486c1369e1d098b7645ab07cd (patch)
tree39accfea009e495729b4daa51a978b432f2a9b67 /src/net_types.cpp
parent9015d118425df4a5b34455da15334901ece85ed3 (diff)
downloadbitcoin-faa6c3d44c861c0486c1369e1d098b7645ab07cd.tar.xz
net: Drop only invalid entries when reading banlist.json
Currently all entries in the file are dropped. Fix that by only dropping the invalid ones
Diffstat (limited to 'src/net_types.cpp')
-rw-r--r--src/net_types.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/net_types.cpp b/src/net_types.cpp
index c8f57fe6c6..e4101a9876 100644
--- a/src/net_types.cpp
+++ b/src/net_types.cpp
@@ -4,12 +4,16 @@
#include <net_types.h>
+#include <logging.h>
#include <netaddress.h>
#include <netbase.h>
#include <univalue.h>
+static const char* BANMAN_JSON_VERSION_KEY{"version"};
+
CBanEntry::CBanEntry(const UniValue& json)
- : nVersion(json["version"].get_int()), nCreateTime(json["ban_created"].get_int64()),
+ : nVersion(json[BANMAN_JSON_VERSION_KEY].get_int()),
+ nCreateTime(json["ban_created"].get_int64()),
nBanUntil(json["banned_until"].get_int64())
{
}
@@ -17,7 +21,7 @@ CBanEntry::CBanEntry(const UniValue& json)
UniValue CBanEntry::ToJson() const
{
UniValue json(UniValue::VOBJ);
- json.pushKV("version", nVersion);
+ json.pushKV(BANMAN_JSON_VERSION_KEY, nVersion);
json.pushKV("ban_created", nCreateTime);
json.pushKV("banned_until", nBanUntil);
return json;
@@ -54,11 +58,16 @@ UniValue BanMapToJson(const banmap_t& bans)
void BanMapFromJson(const UniValue& bans_json, banmap_t& bans)
{
for (const auto& ban_entry_json : bans_json.getValues()) {
+ const int version{ban_entry_json[BANMAN_JSON_VERSION_KEY].get_int()};
+ if (version != CBanEntry::CURRENT_VERSION) {
+ LogPrintf("Dropping entry with unknown version (%s) from ban list\n", version);
+ continue;
+ }
CSubNet subnet;
const auto& subnet_str = ban_entry_json[BANMAN_JSON_ADDR_KEY].get_str();
if (!LookupSubNet(subnet_str, subnet)) {
- throw std::runtime_error(
- strprintf("Cannot parse banned address or subnet: %s", subnet_str));
+ LogPrintf("Dropping entry with unparseable address or subnet (%s) from ban list\n", subnet_str);
+ continue;
}
bans.insert_or_assign(subnet, CBanEntry{ban_entry_json});
}