docker_container: fail if there are too many parts in a parsed port (#367)

* Fail if there are too many parts in a parsed port.

* Add tests.

* Prevent bad parsing.
This commit is contained in:
Felix Fontein
2022-05-22 17:20:05 +02:00
committed by GitHub
parent ab2d33aa99
commit 401a76ff00
3 changed files with 51 additions and 0 deletions
+3
View File
@@ -1835,6 +1835,9 @@ class TaskParameters(DockerBaseClass):
port_binds = [(ipaddr, port) for port in parse_port_range(parts[1], self.client)]
else:
port_binds = len(container_ports) * [(ipaddr,)]
else:
self.fail(('Invalid port description "%s" - expected 1 to 3 colon-separated parts, but got %d. '
'Maybe you forgot to use square brackets ([...]) around an IPv6 address?') % (port, p_len))
for bind, container_port in zip(port_binds, container_ports):
idx = '{0}/{1}'.format(container_port, protocol) if protocol else container_port