Skip to content

Commit b99f1f2

Browse files
committed
p2p, rpc: don't allow past absolute timestamp in setban
1 parent adc41cf commit b99f1f2

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/rpc/net.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,10 @@ static RPCHelpMan setban()
741741

742742
const bool absolute{request.params[3].isNull() ? false : request.params[3].get_bool()};
743743

744+
if (absolute && banTime < GetTime()) {
745+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Absolute timestamp is in the past");
746+
}
747+
744748
if (isSubnet) {
745749
node.banman->Ban(subNet, banTime, absolute);
746750
if (node.connman) {

test/functional/p2p_disconnect_ban.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def run_test(self):
4646
assert_raises_rpc_error(-30, "Error: Invalid IP/Subnet", self.nodes[1].setban, "127.0.0.1/42", "add")
4747
assert_equal(len(self.nodes[1].listbanned()), 1) # still only one banned ip because 127.0.0.1 is within the range of 127.0.0.0/24
4848

49+
self.log.info("setban: fail to ban with past absolute timestamp")
50+
assert_raises_rpc_error(-8, "Error: Absolute timestamp is in the past", self.nodes[1].setban, "127.27.0.1", "add", 123, True)
51+
4952
self.log.info("setban remove: fail to unban a non-banned subnet")
5053
assert_raises_rpc_error(-30, "Error: Unban failed", self.nodes[1].setban, "127.0.0.1", "remove")
5154
assert_equal(len(self.nodes[1].listbanned()), 1)

0 commit comments

Comments
 (0)