commit 8056721cbb75a717604a1f7971440726d9d85045 Author: Peter Krempa Date: Thu Nov 9 12:51:25 2017 +0100 qemu: Tolerate storage source private data being NULL In some cases it does not make sense to pursue that the private data will be allocated (especially when we don't need to put anything in it). Ensure that the code works without it. This also fixes few crashes pointed out in https://bugzilla.redhat.com/show_bug.cgi?id=1510323 Index: libvirt-3.9.0/src/qemu/qemu_command.c =================================================================== --- libvirt-3.9.0.orig/src/qemu/qemu_command.c +++ libvirt-3.9.0/src/qemu/qemu_command.c @@ -1362,12 +1362,17 @@ qemuBuildDriveSourceStr(virDomainDiskDef { int actualType = virStorageSourceGetActualType(disk->src); qemuDomainStorageSourcePrivatePtr srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src); - qemuDomainSecretInfoPtr secinfo = srcpriv->secinfo; - qemuDomainSecretInfoPtr encinfo = srcpriv->encinfo; + qemuDomainSecretInfoPtr secinfo = NULL; + qemuDomainSecretInfoPtr encinfo = NULL; virJSONValuePtr srcprops = NULL; char *source = NULL; int ret = -1; + if (srcpriv) { + secinfo = srcpriv->secinfo; + encinfo = srcpriv->encinfo; + } + if (qemuDiskSourceNeedsProps(disk->src) && !(srcprops = qemuDiskSourceGetProps(disk->src))) goto cleanup; @@ -2239,8 +2244,13 @@ qemuBuildDiskDriveCommandLine(virCommand bool driveBoot = false; virDomainDiskDefPtr disk = def->disks[i]; qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src); - qemuDomainSecretInfoPtr secinfo = srcPriv->secinfo; - qemuDomainSecretInfoPtr encinfo = srcPriv->encinfo; + qemuDomainSecretInfoPtr secinfo = NULL; + qemuDomainSecretInfoPtr encinfo = NULL; + + if (srcPriv) { + secinfo = srcPriv->secinfo; + encinfo = srcPriv->encinfo; + } if (disk->info.bootIndex) { bootindex = disk->info.bootIndex; Index: libvirt-3.9.0/src/qemu/qemu_hotplug.c =================================================================== --- libvirt-3.9.0.orig/src/qemu/qemu_hotplug.c +++ libvirt-3.9.0/src/qemu/qemu_hotplug.c @@ -259,6 +259,7 @@ qemuDomainChangeEjectableMedia(virQEMUDr qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src); + qemuDomainSecretInfoPtr secinfo = NULL; const char *format = NULL; char *sourcestr = NULL; @@ -268,6 +269,9 @@ qemuDomainChangeEjectableMedia(virQEMUDr goto cleanup; } + if (srcPriv) + secinfo = srcPriv->secinfo; + if (disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY && disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -300,7 +304,7 @@ qemuDomainChangeEjectableMedia(virQEMUDr } if (!virStorageSourceIsEmpty(newsrc)) { - if (qemuGetDriveSourceString(newsrc, srcPriv->secinfo, &sourcestr) < 0) + if (qemuGetDriveSourceString(newsrc, secinfo, &sourcestr) < 0) goto error; if (virStorageSourceGetActualType(newsrc) != VIR_STORAGE_TYPE_DIR) { @@ -371,8 +375,8 @@ qemuDomainAttachDiskGeneric(virConnectPt virJSONValuePtr secobjProps = NULL; virJSONValuePtr encobjProps = NULL; qemuDomainStorageSourcePrivatePtr srcPriv; - qemuDomainSecretInfoPtr secinfo; - qemuDomainSecretInfoPtr encinfo; + qemuDomainSecretInfoPtr secinfo = NULL; + qemuDomainSecretInfoPtr encinfo = NULL; if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false) < 0) goto cleanup; @@ -384,13 +388,16 @@ qemuDomainAttachDiskGeneric(virConnectPt goto error; srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src); - secinfo = srcPriv->secinfo; + if (srcPriv) { + secinfo = srcPriv->secinfo; + encinfo = srcPriv->encinfo; + } + if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) { if (qemuBuildSecretInfoProps(secinfo, &secobjProps) < 0) goto error; } - encinfo = srcPriv->encinfo; if (encinfo && qemuBuildSecretInfoProps(encinfo, &encobjProps) < 0) goto error;