]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hostdev: Update mdev pointer reference after checking device type
authorErik Skultety <eskultet@redhat.com>
Thu, 7 Jan 2021 15:48:40 +0000 (16:48 +0100)
committerErik Skultety <eskultet@redhat.com>
Fri, 8 Jan 2021 07:08:29 +0000 (08:08 +0100)
We set the pointer to some garbage packed structure data without
knowing whether we were actually handling the type of device we
expected to be handling. On its own, this was harmless, because we'd
never use the pointer as we'd skip the device if it were not the
expected type. However, it's better to make the logic even more
explicit - we first check the device and only when we're sure we have
the expected type we then update the pointer shortcut.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/hypervisor/virhostdev.c

index 120187b07a26de369c09dd1eee62b360694b9407..aa3fc8738fe15efec0e29af60ca290861f1df6fd 100644 (file)
@@ -1980,11 +1980,11 @@ virHostdevReAttachMediatedDevices(virHostdevManagerPtr mgr,
         virDomainHostdevSubsysMediatedDevPtr mdevsrc;
         virDomainHostdevDefPtr hostdev = hostdevs[i];
 
-        mdevsrc = &hostdev->source.subsys.u.mdev;
-
         if (!virHostdevIsMdevDevice(hostdev))
             continue;
 
+        mdevsrc = &hostdev->source.subsys.u.mdev;
+
         if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
                                           mdevsrc->model)))
             continue;