@@ -263,6 +263,16 @@ def check_announcement_of_new_block(node, peer, predicate):
263263 test_node .send_and_ping (msg_sendcmpct (announce = False , version = 2 ))
264264 check_announcement_of_new_block (node , test_node , lambda p : "cmpctblock" not in p .last_message and "headers" in p .last_message )
265265
266+ # BIP152 mandates that the announce field of a sendcmpct message is a
267+ # boolean and MUST have a value of either 1 or 0. Sending any other value
268+ # should be treated as misbehavior and lead to a disconnect.
269+ def test_invalid_sendcmpct_announce (self ):
270+ node = self .nodes [0 ]
271+ bad_peer = node .add_p2p_connection (TestP2PConn ())
272+ msg = msg_sendcmpct (announce = 2 , version = 2 )
273+ with node .assert_debug_log (['invalid sendcmpct announce field' ]):
274+ bad_peer .send_await_disconnect (msg )
275+
266276 # This test actually causes bitcoind to (reasonably!) disconnect us, so do this last.
267277 def test_invalid_cmpctblock_message (self ):
268278 self .generate (self .nodes [0 ], COINBASE_MATURITY + 1 )
@@ -1017,6 +1027,9 @@ def run_test(self):
10171027 # The previous test will lead to a disconnection. Reconnect before continuing.
10181028 self .segwit_node = self .nodes [0 ].add_p2p_connection (TestP2PConn ())
10191029
1030+ self .log .info ("Testing invalid announce field in sendcmpct message..." )
1031+ self .test_invalid_sendcmpct_announce ()
1032+
10201033 self .log .info ("Testing invalid index in cmpctblock message..." )
10211034 self .test_invalid_cmpctblock_message ()
10221035
0 commit comments