From b5c12fb1f1e0b7a145bb5b2682db737316084003 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Mon, 17 Apr 2023 01:07:12 -0400 Subject: [PATCH] tests: use `shlex.quote` to pass command arg to vtysh This makes sure any included quotation is properly escaped and passed through to vtysh. Signed-off-by: Christian Hopps --- tests/topotests/lib/topogen.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index f5b3ad06d9..d505317e4e 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -33,6 +33,7 @@ import os import platform import pwd import re +import shlex import subprocess import sys from collections import OrderedDict @@ -946,9 +947,11 @@ class TopoRouter(TopoGear): if daemon is not None: dparam += "-d {}".format(daemon) - vtysh_command = 'vtysh {} -c "{}" 2>/dev/null'.format(dparam, command) + vtysh_command = "vtysh {} -c {} 2>/dev/null".format( + dparam, shlex.quote(command) + ) - self.logger.debug('vtysh command => "{}"'.format(command)) + self.logger.debug("vtysh command => {}".format(shlex.quote(command))) output = self.run(vtysh_command) dbgout = output.strip() -- 2.39.5