fix(ping): quote the destination and source in the ping command
ping() typed its arguments into the interactive shell as they came, so a destination such as "1.2.3.4; id" ran the command after the semicolon as the login user. destination and source now go through shlex.quote, and count, timeout, size and ttl are coerced with int(), which refuses anything that is not a number before a command is sent. The command is built in _ping.py, next to its parser, which keeps linux.py within its recorded length. Closes #55
This commit is contained in:
1 parent
5687f5d9a1
commit
c2d7c4d1b4
5 files changed
+51
-6
No files matched your search
@@ -74,7 +74,7 @@ from netmiko.exceptions import NetmikoAuthenticationException, NetmikoTimeoutExc
|
||||
from napalm_linux._dpkg import DPKG_QUERY_COMMAND, parse_dpkg_query
|
||||
from napalm_linux._hostname import HostnameMixin
|
||||
from napalm_linux._local_accounts import LinuxLocalAccountsMixin
|
||||
from napalm_linux._ping import parse_ping
|
||||
from napalm_linux._ping import parse_ping, ping_command
|
||||
from napalm_linux._routes import IP_ROUTE_COMMANDS, parse_ip_route
|
||||
from napalm_linux._shell import expect_for, prepare_shell
|
||||
from napalm_linux._sudo_history import LinuxSudoHistoryMixin
|
||||
@@ -1086,10 +1086,8 @@ class LinuxDriver(
|
||||
count: int = 5,
|
||||
vrf: str = "",
|
||||
) -> dict[str, Any]:
|
||||
"""Execute ping from the remote host."""
|
||||
src_opt = f"-I {source}" if source else ""
|
||||
cmd = f"ping -c {count} -W {timeout} -s {size} -t {ttl} {src_opt} {destination} 2>&1"
|
||||
return parse_ping(self._send(cmd))
|
||||
"""Ping from the remote host; ValueError for a count, timeout, size or ttl not a number."""
|
||||
return parse_ping(self._send(ping_command(destination, source, ttl, timeout, size, count)))
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# KernelFactsMixin – the transport for get_kernel_facts
|
||||
|
||||
Reference in new issue
Block a user