[PATCH 0/2] conf: Don't crash when one of disks is missing

Peter Krempa (2): virDomainDiskInsert: Don't access NULL disk target qemuxml2argvtest: disk-missing-target: Add two disks with same bus src/conf/domain_conf.c | 1 + tests/qemuxml2argvdata/disk-missing-target-invalid.xml | 3 +++ 2 files changed, 4 insertions(+) -- 2.31.1

'virDomainDiskInsert' orders the inserted disks by target. If the target is not provided though it would try to parse it anyways. This lead to a crash when parsing a definition where there are multiple disks and of two disks sharing the bus at least one also misses the target. Since we want to actually use the parser for stuff which doesn't necessarily need the disk target, we make virDomainDiskInsert tolerant of missing target instead. The definition will be rejected by the validator regardless of the order the disks were inserted in. Fixes: 61fd7174 Closes: https://gitlab.com/libvirt/libvirt/-/issues/257 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/domain_conf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9a21ac10ce..e0c92816f1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15653,6 +15653,7 @@ void virDomainDiskInsert(virDomainDef *def, /* If bus matches and current disk is after * new disk, then new disk should go here */ if (def->disks[idx]->bus == disk->bus && + def->disks[idx]->dst && disk->dst && (virDiskNameToIndex(def->disks[idx]->dst) > virDiskNameToIndex(disk->dst))) { insertAt = idx; -- 2.31.1

A recent code movement introduced a bug which reproduces only when there are two disks on the same bus missing the target. Improve the test case for the missing target test. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/qemuxml2argvdata/disk-missing-target-invalid.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/qemuxml2argvdata/disk-missing-target-invalid.xml b/tests/qemuxml2argvdata/disk-missing-target-invalid.xml index 49cd73142a..11287f2afb 100644 --- a/tests/qemuxml2argvdata/disk-missing-target-invalid.xml +++ b/tests/qemuxml2argvdata/disk-missing-target-invalid.xml @@ -17,6 +17,9 @@ <disk type='block' device='disk'> <source dev='/dev/HostVG/QEMUGuest1'/> </disk> + <disk type='block' device='disk'> + <source dev='/dev/HostVG/QEMUGuest2'/> + </disk> <memballoon model='virtio'/> </devices> </domain> -- 2.31.1

On a Thursday in 2021, Peter Krempa wrote:
Peter Krempa (2): virDomainDiskInsert: Don't access NULL disk target qemuxml2argvtest: disk-missing-target: Add two disks with same bus
src/conf/domain_conf.c | 1 + tests/qemuxml2argvdata/disk-missing-target-invalid.xml | 3 +++ 2 files changed, 4 insertions(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Peter Krempa