aboutsummaryrefslogtreecommitdiff
path: root/scripts/qemu.py
diff options
context:
space:
mode:
authorLukáš Doktor <ldoktor@redhat.com>2017-08-18 16:26:05 +0200
committerEduardo Habkost <ehabkost@redhat.com>2017-09-15 20:12:00 -0300
commit2782fc517d6720dbec24b4dfa08aa4606c72c76d (patch)
tree5044cb0bf5a054d8abe887cff1d20bf5390d453e /scripts/qemu.py
parent2d853c70a25a2c4b812eadd304c9e35882eb2e0e (diff)
downloadqemu-2782fc517d6720dbec24b4dfa08aa4606c72c76d.zip
qemu-2782fc517d6720dbec24b4dfa08aa4606c72c76d.tar.gz
qemu-2782fc517d6720dbec24b4dfa08aa4606c72c76d.tar.bz2
qemu|qtest: Avoid dangerous arguments
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 <ldoktor@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com> Message-Id: <20170818142613.32394-3-ldoktor@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Diffstat (limited to 'scripts/qemu.py')
-rw-r--r--scripts/qemu.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/scripts/qemu.py b/scripts/qemu.py
index b45e691..afd98a2 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -30,7 +30,7 @@ class QEMUMachine(object):
# vm is guaranteed to be shut down here
'''
- def __init__(self, binary, args=[], wrapper=[], name=None,
+ def __init__(self, binary, args=None, wrapper=None, name=None,
test_dir="/var/tmp", monitor_address=None,
socket_scm_helper=None, debug=False):
'''
@@ -46,6 +46,10 @@ class QEMUMachine(object):
@param debug: enable debug mode
@note: Qemu process is not started until launch() is used.
'''
+ if args is None:
+ args = []
+ if wrapper is None:
+ wrapper = []
if name is None:
name = "qemu-%d" % os.getpid()
if monitor_address is None: