From 2782fc517d6720dbec24b4dfa08aa4606c72c76d Mon Sep 17 00:00:00 2001 From: Lukáš Doktor Date: Fri, 18 Aug 2017 16:26:05 +0200 Subject: qemu|qtest: Avoid dangerous arguments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The list object is mutable in python and potentially might modify other object's arguments when used as default argument. Reproducer: >>> vm1 = QEMUMachine("qemu") >>> vm2 = QEMUMachine("qemu") >>> vm1._wrapper.append("foo") >>> print vm2._wrapper ['foo'] In this case the `args` is actually copied so it would be safe to keep it, but it's not a good practice to keep it. The same issue applies in inherited qtest module. Signed-off-by: Lukáš Doktor Reviewed-by: Eduardo Habkost Reviewed-by: John Snow Message-Id: <20170818142613.32394-3-ldoktor@redhat.com> Reviewed-by: Cleber Rosa Signed-off-by: Eduardo Habkost --- scripts/qtest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/qtest.py') diff --git a/scripts/qtest.py b/scripts/qtest.py index d5aecb5f49..ab183c0635 100644 --- a/scripts/qtest.py +++ b/scripts/qtest.py @@ -79,7 +79,7 @@ class QEMUQtestProtocol(object): class QEMUQtestMachine(qemu.QEMUMachine): '''A QEMU VM''' - def __init__(self, binary, args=[], name=None, test_dir="/var/tmp", + def __init__(self, binary, args=None, name=None, test_dir="/var/tmp", socket_scm_helper=None): if name is None: name = "qemu-%d" % os.getpid() -- cgit 1.4.1 From 4d9342977a2e8b195609d332fcd64a93a48c158b Mon Sep 17 00:00:00 2001 From: Lukáš Doktor Date: Fri, 18 Aug 2017 16:26:13 +0200 Subject: qtest.py: Few pylint/style fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No actual code changes, just few pylint/style fixes. Signed-off-by: Lukáš Doktor Reviewed-by: John Snow Message-Id: <20170818142613.32394-11-ldoktor@redhat.com> Signed-off-by: Eduardo Habkost --- scripts/qtest.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'scripts/qtest.py') diff --git a/scripts/qtest.py b/scripts/qtest.py index ab183c0635..df0daf26ca 100644 --- a/scripts/qtest.py +++ b/scripts/qtest.py @@ -11,14 +11,11 @@ # Based on qmp.py. # -import errno import socket -import string import os -import subprocess -import qmp.qmp import qemu + class QEMUQtestProtocol(object): def __init__(self, address, server=False): """ @@ -83,8 +80,10 @@ class QEMUQtestMachine(qemu.QEMUMachine): socket_scm_helper=None): if name is None: name = "qemu-%d" % os.getpid() - super(QEMUQtestMachine, self).__init__(binary, args, name=name, test_dir=test_dir, - socket_scm_helper=socket_scm_helper) + super(QEMUQtestMachine, + self).__init__(binary, args, name=name, test_dir=test_dir, + socket_scm_helper=socket_scm_helper) + self._qtest = None self._qtest_path = os.path.join(test_dir, name + "-qtest.sock") def _base_args(self): -- cgit 1.4.1