[PATCH] qemuDomainAttachDiskGenericTransient: Add NULL check in case the overlay disk already exists

Masayoshi Mizuma posted 1 patch 2 years, 11 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20210526201922.460819-1-msys.mizuma@gmail.com
src/qemu/qemu_hotplug.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] qemuDomainAttachDiskGenericTransient: Add NULL check in case the overlay disk already exists
Posted by Masayoshi Mizuma 2 years, 11 months ago
From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>

When <transient shareBacking='yes'> is set to a disk and the overlay
disk already exists because of something abnormal, libvirt is terminated
by Segmentation fault.

  # virsh start Test0
  error: Disconnected from qemu:///system due to end of file
  error: Failed to start domain 'Test0'
  error: End of file while reading data: Input/output error

Add NULL check for snapdiskdef so that the rollback can work correctly.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
---
 src/qemu/qemu_hotplug.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 9ff6175dd3..0640cdd9f7 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -695,7 +695,9 @@ qemuDomainAttachDiskGenericTransient(virDomainObj *vm,
     g_autoptr(qemuSnapshotDiskContext) snapctxt = NULL;
     g_autoptr(virDomainSnapshotDiskDef) snapdiskdef = NULL;
 
-    snapdiskdef = qemuSnapshotGetTransientDiskDef(disk, vm->def->name);
+    if (!(snapdiskdef = qemuSnapshotGetTransientDiskDef(disk, vm->def->name)))
+        return NULL;
+
     snapctxt = qemuSnapshotDiskContextNew(1, vm, asyncJob);
 
     if (qemuSnapshotDiskPrepareOne(snapctxt, disk, snapdiskdef,
-- 
2.27.0

Re: [PATCH] qemuDomainAttachDiskGenericTransient: Add NULL check in case the overlay disk already exists
Posted by Ján Tomko 2 years, 11 months ago
On a Wednesday in 2021, Masayoshi Mizuma wrote:
>From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
>
>When <transient shareBacking='yes'> is set to a disk and the overlay
>disk already exists because of something abnormal, libvirt is terminated
>by Segmentation fault.
>
>  # virsh start Test0
>  error: Disconnected from qemu:///system due to end of file
>  error: Failed to start domain 'Test0'
>  error: End of file while reading data: Input/output error
>
>Add NULL check for snapdiskdef so that the rollback can work correctly.
>
>Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
>---
> src/qemu/qemu_hotplug.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano