]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Alter condition to avoid possible NULL deref
authorJohn Ferlan <jferlan@redhat.com>
Fri, 9 Feb 2018 13:52:10 +0000 (08:52 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 12 Feb 2018 13:08:48 +0000 (08:08 -0500)
Commit 'f0f2a5ec2' neglected to adjust the if condition to split
out the possibility that the @watchdog is NULL when altering the
message to add detail about the model.

Just split out the condition and use previous/original message, but
with the new message code.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_hotplug.c

index c7bf25eeefefeafb2de086f4031facdacb0e6908..3291ce6130fe264d89bb6b83f90ae2ebb73603e6 100644 (file)
@@ -5159,11 +5159,16 @@ qemuDomainDetachWatchdog(virQEMUDriverPtr driver,
     virDomainWatchdogDefPtr watchdog = vm->def->watchdog;
     qemuDomainObjPrivatePtr priv = vm->privateData;
 
+    if (!watchdog) {
+        virReportError(VIR_ERR_DEVICE_MISSING, "%s",
+                       _("watchdog device not present in domain configuration"));
+        return -1;
+    }
+
     /* While domains can have up to one watchdog, the one supplied by the user
      * doesn't necessarily match the one domain has. Refuse to detach in such
      * case. */
-    if (!(watchdog &&
-          watchdog->model == dev->model &&
+    if (!(watchdog->model == dev->model &&
           watchdog->action == dev->action &&
           virDomainDeviceInfoAddressIsEqual(&dev->info, &watchdog->info))) {
         virReportError(VIR_ERR_DEVICE_MISSING,