Dont accept peers too large
This commit is contained in:
parent
12d4ed7638
commit
0b4e264877
@ -23,6 +23,8 @@ def _ask_peer(peer):
|
|||||||
peer = b''
|
peer = b''
|
||||||
c = b''
|
c = b''
|
||||||
while c != b'\n':
|
while c != b'\n':
|
||||||
|
if len(peer) > TRANSPORT_SIZE_BYTES:
|
||||||
|
raise OverflowError
|
||||||
c = s.recv(1)
|
c = s.recv(1)
|
||||||
peer += c
|
peer += c
|
||||||
if not peer:
|
if not peer:
|
||||||
|
@ -47,9 +47,10 @@ class MockPeer:
|
|||||||
s.connect(server_file)
|
s.connect(server_file)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
fake_peer_addresses = [MockPeer().transport_address for i in range(10)]
|
||||||
|
|
||||||
|
|
||||||
def _server():
|
def _server():
|
||||||
fake_peer_addresses = [MockPeer().transport_address for i in range(10)]
|
|
||||||
|
|
||||||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s:
|
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s:
|
||||||
s.bind(server_file)
|
s.bind(server_file)
|
||||||
@ -58,7 +59,7 @@ def _server():
|
|||||||
with conn:
|
with conn:
|
||||||
conn.recv(1)
|
conn.recv(1)
|
||||||
for address in fake_peer_addresses:
|
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()
|
Thread(target=_server, daemon=True).start()
|
||||||
@ -74,6 +75,7 @@ class OnionrGossipClientGetNewPeers(unittest.TestCase):
|
|||||||
p = MockPeer()
|
p = MockPeer()
|
||||||
gossip_peer_set.add(p)
|
gossip_peer_set.add(p)
|
||||||
get_new_peers()
|
get_new_peers()
|
||||||
|
self.assertTrue(len(gossip_peer_set), len(fake_peer_addresses) + 1)
|
||||||
|
|
||||||
|
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user