[PATCH v2 1/5] qemuSnapshotDiskHasBackingDisk: Avoid call of virStorageSourceIsSameLocation with NULL argument

Peter Krempa via Devel posted 5 patches 6 days, 13 hours ago
[PATCH v2 1/5] qemuSnapshotDiskHasBackingDisk: Avoid call of virStorageSourceIsSameLocation with NULL argument
Posted by Peter Krempa via Devel 6 days, 13 hours ago
From: Peter Krempa <pkrempa@redhat.com>

When the 'backingStore' pointer is not populated the function calls
'virStorageSourceGetMetadata' to try to populate it but if the on-disk
metadata doesn't have a backing image (e.g. if it's the 'base' image of
the chain) the 'backingStore' or the metadata fetcher fails the pointer
will still be NULL.

The function then calls 'virStorageSourceIsSameLocation' but the
internal functions for dealing with storage sources don't handle NULL
gracefully.

Since the code calling 'qemu-img' based on the data detected here
doesn't actually raise errors if the operations fail there's no point
in raising errors here either.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/844
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_snapshot.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index e738afffc3..8f58df3b45 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -3147,7 +3147,8 @@ qemuSnapshotDiskHasBackingDisk(void *payload,
         if (!disk->src->backingStore)
             ignore_value(virStorageSourceGetMetadata(disk->src, uid, gid, 1, false));

-        if (virStorageSourceIsSameLocation(disk->src->backingStore, iterdata->diskSrc)) {
+        if (disk->src->backingStore &&
+            virStorageSourceIsSameLocation(disk->src->backingStore, iterdata->diskSrc)) {
             struct _qemuSnapshotDisksWithBackingStoreData *data =
                 g_new0(struct _qemuSnapshotDisksWithBackingStoreData, 1);

-- 
2.52.0