提交 014867f3 编写于 作者: L Lukáš Doktor

avocado.utils.process: Improve detection to run cmd in GDB

shlex.split() can fail on some strange commands (eg. on an unfinished
quotation). This patch fallbacks to simple string.split() in such cases,
which might return incorrect results, but is safer to use. Although it
logs warning about this notifying the user about possible issue.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 d6bbf150
......@@ -864,11 +864,15 @@ def should_run_inside_gdb(cmd):
:param cmd: the command arguments, from where we extract the binary name
"""
if not gdb.GDB_RUN_BINARY_NAMES_EXPR:
return False
try:
args = shlex.split(cmd)
except ValueError:
return False
log.warning("Unable to check whether command '%s' should run inside "
"GDB, fallback to simplified method...", cmd)
args = cmd.split()
cmd_binary_name = os.path.basename(args[0])
for expr in gdb.GDB_RUN_BINARY_NAMES_EXPR:
......
......@@ -36,7 +36,9 @@ class TestGDBProcess(unittest.TestCase):
def test_should_run_inside_gdb_malformed_command(self):
gdb.GDB_RUN_BINARY_NAMES_EXPR = ['/bin/virsh']
cmd = """/bin/virsh node-memory-tune --shm-sleep-millisecs ~!@#$%^*()-=[]{}|_+":;'`,>?. """
self.assertFalse(process.should_run_inside_gdb(cmd))
self.assertTrue(process.should_run_inside_gdb(cmd))
self.assertFalse(process.should_run_inside_gdb("foo bar baz"))
self.assertFalse(process.should_run_inside_gdb("foo ' "))
def test_get_sub_process_klass(self):
gdb.GDB_RUN_BINARY_NAMES_EXPR = []
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册