fix(ping): refuse a destination or source that reads as an option
Quoting keeps a value one word, but ping still reads a word starting with "-" as one of its options: ping(destination="-f") sent a flood ping option instead of a host, and a source "-f" did the same after -I. No address or hostname starts with "-", so ping_command now refuses such a destination or source with ValueError before anything is sent. Closes #63
This commit is contained in:
1 parent
e4c65945b9
commit
a1e8ec78c3
4 files changed
+22
-3
No files matched your search
@@ -27,8 +27,13 @@ def ping_command(
|
||||
) -> str:
|
||||
"""The shell line that pings *destination*: the names quoted, the numbers numbers (#55).
|
||||
|
||||
:raises ValueError: for a count, timeout, size or ttl that is no number.
|
||||
:raises ValueError: for a count, timeout, size or ttl that is no number, and for a
|
||||
destination or source that ping would read as an option (#63): no address or
|
||||
hostname starts with ``-``.
|
||||
"""
|
||||
for name in (destination, source):
|
||||
if name.startswith("-"):
|
||||
raise ValueError(f"{name!r} would be read as a ping option, not an address")
|
||||
numbers = f"-c {int(count)} -W {int(timeout)} -s {int(size)} -t {int(ttl)}"
|
||||
src_opt = f" -I {quote(source)}" if source else ""
|
||||
return f"ping {numbers}{src_opt} {quote(destination)} 2>&1"
|
||||
|
||||
@@ -1086,7 +1086,7 @@ class LinuxDriver(
|
||||
count: int = 5,
|
||||
vrf: str = "",
|
||||
) -> dict[str, Any]:
|
||||
"""Ping from the remote host; ValueError for a count, timeout, size or ttl not a number."""
|
||||
"""Ping from the remote host; ValueError for a bad number or a name starting with -."""
|
||||
return parse_ping(self._send(ping_command(destination, source, ttl, timeout, size, count)))
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user