mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-27 06:19:09 +01:00
qa: Add tests for invalid message headers
This commit is contained in:
@@ -118,7 +118,7 @@ class P2PConnection(asyncio.Protocol):
|
||||
# The initial message to send after the connection was made:
|
||||
self.on_connection_send_msg = None
|
||||
self.recvbuf = b""
|
||||
self.network = net
|
||||
self.magic_bytes = MAGIC_BYTES[net]
|
||||
logger.debug('Connecting to Bitcoin Node: %s:%d' % (self.dstaddr, self.dstport))
|
||||
|
||||
loop = NetworkThread.network_event_loop
|
||||
@@ -170,7 +170,7 @@ class P2PConnection(asyncio.Protocol):
|
||||
while True:
|
||||
if len(self.recvbuf) < 4:
|
||||
return
|
||||
if self.recvbuf[:4] != MAGIC_BYTES[self.network]:
|
||||
if self.recvbuf[:4] != self.magic_bytes:
|
||||
raise ValueError("got garbage %s" % repr(self.recvbuf))
|
||||
if len(self.recvbuf) < 4 + 12 + 4 + 4:
|
||||
return
|
||||
@@ -232,7 +232,7 @@ class P2PConnection(asyncio.Protocol):
|
||||
"""Build a serialized P2P message"""
|
||||
command = message.command
|
||||
data = message.serialize()
|
||||
tmsg = MAGIC_BYTES[self.network]
|
||||
tmsg = self.magic_bytes
|
||||
tmsg += command
|
||||
tmsg += b"\x00" * (12 - len(command))
|
||||
tmsg += struct.pack("<I", len(data))
|
||||
|
||||
Reference in New Issue
Block a user