From 0f377eb1b0c48783ba29ee9c5df3aeef9f9926b3 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Fri, 22 Apr 2016 10:40:57 -0400 Subject: [PATCH] qemu: command: escape commas in VM name This isn't sufficient on its own, since the VM name is used for things like monitor paths, which we don't escape yet --- src/qemu/qemu_command.c | 2 +- .../qemuxml2argv-name-escape.args | 24 +++++++++++++++++++ .../qemuxml2argv-name-escape.xml | 18 ++++++++++++++ tests/qemuxml2argvtest.c | 2 ++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-name-escape.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-name-escape.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 4745ecac47..02bd543eeb 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6867,7 +6867,7 @@ qemuBuildNameCommandLine(virCommandPtr cmd, virCommandAddArg(cmd, "-name"); - virBufferAsprintf(&buf, "%s", def->name); + qemuBufferEscapeComma(&buf, def->name); if (cfg->setProcessName && virQEMUCapsGet(qemuCaps, QEMU_CAPS_NAME_PROCESS)) diff --git a/tests/qemuxml2argvdata/qemuxml2argv-name-escape.args b/tests/qemuxml2argvdata/qemuxml2argv-name-escape.args new file mode 100644 index 0000000000..94a3133a8a --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-name-escape.args @@ -0,0 +1,24 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu \ +-name foo,,bar,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-foo,\ +bar/master-key.aes \ +-M pc \ +-m 214 \ +-smp 1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefaults \ +-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-foo,bar/monitor.sock,\ +server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=readline \ +-no-acpi \ +-boot c \ +-usb \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-name-escape.xml b/tests/qemuxml2argvdata/qemuxml2argv-name-escape.xml new file mode 100644 index 0000000000..3a8c3cd56d --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-name-escape.xml @@ -0,0 +1,18 @@ + + foo,bar + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index d1cfbecb9a..bed6a71b96 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1902,6 +1902,8 @@ mymain(void) VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS, NONE); + DO_TEST("name-escape", QEMU_CAPS_NAME_DEBUG_THREADS, + QEMU_CAPS_OBJECT_SECRET, QEMU_CAPS_CHARDEV); DO_TEST("debug-threads", QEMU_CAPS_NAME_DEBUG_THREADS); DO_TEST("master-key", QEMU_CAPS_OBJECT_SECRET);