]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virDomainDiskInsert: Don't access NULL disk target
authorPeter Krempa <pkrempa@redhat.com>
Thu, 16 Dec 2021 13:14:43 +0000 (14:14 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 16 Dec 2021 14:58:06 +0000 (15:58 +0100)
'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>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c

index 9a21ac10ceb02c4f457a6fd40055cbc65d009138..e0c92816f1ed26caa371859724963c0107f152a2 100644 (file)
@@ -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;