Validate reversed telnet console port ranges (#7593)

This commit is contained in:
Syncrain 2026-06-11 13:17:00 +05:30 committed by GitHub
parent 2d0a898e2d
commit ba28630c98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View File

@ -33,6 +33,8 @@ def listen_tcp(portrange: list[int], host: str, factory: ServerFactory) -> Port:
if len(portrange) > 2:
raise ValueError(f"invalid portrange: {portrange}")
if len(portrange) == 2 and portrange[0] > portrange[1]:
raise ValueError(f"invalid portrange: {portrange}")
if not portrange:
return reactor.listenTCP(0, factory, interface=host) # type: ignore[no-any-return]
if len(portrange) == 1:

View File

@ -53,3 +53,9 @@ class TestTelnetExtension:
d = portal.login(creds, None, ITelnetProtocol)
yield d
console.stop_listening()
def test_invalid_reversed_portrange(self):
settings = {"TELNETCONSOLE_PORT": [2, 1]}
console = TelnetConsole(get_crawler(settings_dict=settings))
with pytest.raises(ValueError, match=r"invalid portrange: \[2, 1\]"):
console.start_listening()