]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Add check to avoid a NULL compare for SysfsPath
authorCheng Lin <cheng.lin130@zte.com.cn>
Fri, 18 Jan 2019 07:49:37 +0000 (15:49 +0800)
committerCole Robinson <crobinso@redhat.com>
Thu, 24 Jan 2019 22:31:32 +0000 (17:31 -0500)
If the two sysfs_path are both NULL, there may be an incorrect
object returned for virNodeDeviceObjListFindBySysfsPath().

This check exists in old interface virNodeDeviceFindBySysfsPath().
e.g.
virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs,
                             const char *sysfs_path)
{
    ...
        if ((devs->objs[i]->def->sysfs_path != NULL) &&
            (STREQ(devs->objs[i]->def->sysfs_path, sysfs_path))) {
    ...
}

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Cheng Lin <cheng.lin130@zte.com.cn>
src/conf/virnodedeviceobj.c

index c8ad1314b54fa374f9280e6272f593a60c842b87..6df2985561802df64d7dc4ecf4f2a431c937414e 100644 (file)
@@ -207,7 +207,8 @@ virNodeDeviceObjListFindBySysfsPathCallback(const void *payload,
     int want = 0;
 
     virObjectLock(obj);
-    if (STREQ_NULLABLE(obj->def->sysfs_path, sysfs_path))
+    if (obj->def->sysfs_path &&
+        STREQ_NULLABLE(obj->def->sysfs_path, sysfs_path))
         want = 1;
     virObjectUnlock(obj);
     return want;