ping: a destination or source starting with '-' is read as a ping option #63

Closed
opened 2026-11-02 07:46:33 +00:00 by christianmanivong · 0 comments
Owner

What happens

Since #55, ping_command() (napalm_linux/_ping.py, on PR #61) passes destination and source through shlex.quote:

return f"ping {numbers}{src_opt} {quote(destination)} 2>&1"

Quoting keeps a value one word, but a word that starts with - is still read by ping as an option: shlex.quote("-f") is -f, so ping(destination="-f") sends a flood ping option instead of a host, and other options (-p, -b, …) can be injected the same way. The same holds for source after -I (a value such as -f makes -I consume nothing useful).

Expected

A destination or source that starts with - is refused (ValueError) before anything is sent, or the destination follows --. Test-first: ping("-f") raises / sends -- '-f'.

Priority: P3 — option injection in a public driver method; netOrk passes only addresses from ipaddress (see #55), so not reachable from netOrk's input.

Found during the bug sweep of 2026-11-02 (review of #55).

## What happens Since #55, `ping_command()` (`napalm_linux/_ping.py`, on PR #61) passes `destination` and `source` through `shlex.quote`: ```python return f"ping {numbers}{src_opt} {quote(destination)} 2>&1" ``` Quoting keeps a value one word, but a word that starts with `-` is still read by `ping` as an option: `shlex.quote("-f")` is `-f`, so `ping(destination="-f")` sends a flood ping option instead of a host, and other options (`-p`, `-b`, …) can be injected the same way. The same holds for `source` after `-I` (a value such as `-f` makes `-I` consume nothing useful). ## Expected A destination or source that starts with `-` is refused (`ValueError`) before anything is sent, or the destination follows `--`. Test-first: `ping("-f")` raises / sends `-- '-f'`. Priority: P3 — option injection in a public driver method; netOrk passes only addresses from `ipaddress` (see #55), so not reachable from netOrk's input. Found during the bug sweep of 2026-11-02 (review of #55).
christianmanivong added the
prio
P3
bug
labels 2026-11-02 07:46:33 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-linux#63