fix(interfaces): set_interface refuses a description with line breaks or double quotes (#28)
driver / lint (pull_request) Successful in 15s
driver / standard (pull_request) Failing after 17s
driver / types (pull_request) Successful in 1m2s
driver / test (3.13) (pull_request) Successful in 56s
driver / test (3.12) (pull_request) Successful in 1m3s
driver / lowest (pull_request) Successful in 29s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Successful in 1m8s
CI / driver (pull_request) Failing after 2m21s
driver / publish (pull_request) Skipped

Over SSH the description went into `  name "<desc>"` under
`interface <port>`, one line of a block sent line by line before
`write memory`: a line break ran the rest as commands, a double quote
ended the value. It is the same injection as set_vlan's name
(NetOrk/netork#2455).

set_interface() now raises ValueError for a description containing \r,
\n or ", before anything is sent, over every transport, through the same
check as set_vlan (_check_cli_value). The tests move to
test_cli_values.py, which covers both.
This commit is contained in:
Christian Manivong committed 2026-11-12 23:01:38 +01:00
1 parent c4cd0bbdf3
commit e06811de50
3 files changed
+56 -11

No files matched your search

+11 -6
View File
@@ -89,10 +89,10 @@ _CLI_WORD = re.compile(r'^[^\s"#]+$')
_BREAKS_CLI_VALUE = re.compile(r'[\r\n"]')
def _check_vlan_name(name: str | None) -> None:
"""Refuse a VLAN name that would break out of its ``name "..."`` line (NetOrk/netork#2455)."""
if name is not None and _BREAKS_CLI_VALUE.search(name):
raise ValueError(f"VLAN name {name!r} must be one line without double quotes")
def _check_cli_value(what: str, value: str | None) -> None:
"""Refuse a value that would break out of its ``name "..."`` line (NetOrk/netork#2455)."""
if value is not None and _BREAKS_CLI_VALUE.search(value):
raise ValueError(f"{what} {value!r} must be one line without double quotes")
class ProcurveDriver(ProcurveTimeSyncMixin, ConfigLifecycleMixin, SwitchDriver):
@@ -835,7 +835,7 @@ class ProcurveDriver(ProcurveTimeSyncMixin, ConfigLifecycleMixin, SwitchDriver):
sent, over every transport: over SSH it ended its ``name "..."`` line and
the switch ran the rest as commands.
"""
_check_vlan_name(config.get("name"))
_check_cli_value("VLAN name", config.get("name"))
if self._transport == "api":
self._api_set_vlan(vlan_id, config)
else:
@@ -926,7 +926,12 @@ class ProcurveDriver(ProcurveTimeSyncMixin, ConfigLifecycleMixin, SwitchDriver):
self._save_config()
def set_interface(self, interface: str, config: InterfaceConfigDict) -> None:
"""Configure a switch interface (mode, VLAN membership)."""
"""Configure a switch interface (mode, VLAN membership).
A description with a line break or a double quote is refused before anything
is sent, over every transport: over SSH it ended its ``name "..."`` line.
"""
_check_cli_value("description", config.get("description"))
if self._transport == "api":
self._api_set_interface(interface, config)
else: