Dont accept peers too large

This commit is contained in:
Kevin Froman 2022-05-15 21:54:14 -04:00
parent 12d4ed7638
commit 0b4e264877
2 changed files with 7 additions and 3 deletions

View File

@ -23,6 +23,8 @@ def _ask_peer(peer):
peer = b''
c = b''
while c != b'\n':
if len(peer) > TRANSPORT_SIZE_BYTES:
raise OverflowError
c = s.recv(1)
peer += c
if not peer:

View File

@ -47,10 +47,11 @@ class MockPeer:
s.connect(server_file)
return s
fake_peer_addresses = [MockPeer().transport_address for i in range(10)]
def _server():
fake_peer_addresses = [MockPeer().transport_address for i in range(10)]
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s:
s.bind(server_file)
s.listen(1)
@ -58,7 +59,7 @@ def _server():
with conn:
conn.recv(1)
for address in fake_peer_addresses:
conn.sendall(address.zfill(TRANSPORT_SIZE_BYTES).encode('utf-8'))
conn.sendall(address.encode('utf-8') + b'\n')
Thread(target=_server, daemon=True).start()
@ -74,6 +75,7 @@ class OnionrGossipClientGetNewPeers(unittest.TestCase):
p = MockPeer()
gossip_peer_set.add(p)
get_new_peers()
self.assertTrue(len(gossip_peer_set), len(fake_peer_addresses) + 1)
unittest.main()