[libvirt] [PATCH] qemuBuildVideoCommandLine: Don't access def->videos without check

This function can be called over a domain definition that has no video configured. The tests/qemuxml2argvdata/qemuxml2argv-minimal.xml file could serve as an example. Problem is, before the check that domain has some or none video configured, def->videos is dereferenced causing a segmentation fault in case there's none video configured. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_command.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ba8c216..32d32b1 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3809,7 +3809,7 @@ qemuBuildVideoCommandLine(virCommandPtr cmd, virQEMUCapsPtr qemuCaps) { size_t i; - int primaryVideoType = def->videos[0]->type; + int primaryVideoType; if (!def->nvideos) { /* If we have -device, then we set -nodefaults already */ @@ -3819,6 +3819,8 @@ qemuBuildVideoCommandLine(virCommandPtr cmd, return 0; } + primaryVideoType = def->videos[0]->type; + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIDEO_PRIMARY) && ((primaryVideoType == VIR_DOMAIN_VIDEO_TYPE_VGA && virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VGA)) || -- 2.4.10

On Mon, Mar 14, 2016 at 09:47:05 +0100, Michal Privoznik wrote:
This function can be called over a domain definition that has no video configured. The tests/qemuxml2argvdata/qemuxml2argv-minimal.xml file could serve as an example. Problem is, before the check that domain has some or none video configured, def->videos is dereferenced causing a segmentation fault in case there's none video configured.
Caused by commit 95ca4fe2
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_command.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
ACK Peter

On Mon, Mar 14, 2016 at 10:19:18AM +0100, Peter Krempa wrote:
On Mon, Mar 14, 2016 at 09:47:05 +0100, Michal Privoznik wrote:
This function can be called over a domain definition that has no video configured. The tests/qemuxml2argvdata/qemuxml2argv-minimal.xml file could serve as an example. Problem is, before the check that domain has some or none video configured, def->videos is dereferenced causing a segmentation fault in case there's none video configured.
Caused by commit 95ca4fe2
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_command.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
ACK
Ah, thanks, I was hitting that while doing unrelated stuff :) Fwiw, Tested-by: Christophe Fergeau <cfergeau@redhat.com> Christophe
participants (3)
-
Christophe Fergeau
-
Michal Privoznik
-
Peter Krempa