From: John Ferlan Date: Fri, 24 Nov 2017 13:17:02 +0000 (-0500) Subject: storage: Fix path check in storagePoolLookupByTargetPath X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=d4f80d439ecbdca06dec9fc50d1860b150a6ea4f;p=libvirt.git storage: Fix path check in storagePoolLookupByTargetPath Commit id '5ab746b8' introduced the function as perhaps a copy of storageVolLookupByPath; however, it did not use the @cleanpath variable even though it used the virFileSanitizePath. So in essance the only "check" being done for failure is whether it was possible to strdup the path. Looking at the virStoragePoolDefParseXML one will note that the target.path is stored using the result of virFileSanitizePath. Therefore, this function should sanitize and use the input @path for the argument to storagePoolLookupByTargetPathCallback which is comparing against stored target.path values. Additionally, if there was an error we should use the proper error of VIR_ERR_NO_STORAGE_POOL (instead of VIR_ERR_NO_STORAGE_VOL). --- diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 561ca36f90..699a382817 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1667,7 +1667,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn, storageDriverLock(); if ((obj = virStoragePoolObjListSearch(&driver->pools, storagePoolLookupByTargetPathCallback, - path))) { + cleanpath))) { def = virStoragePoolObjGetDef(obj); pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); virStoragePoolObjEndAPI(&obj); @@ -1675,9 +1675,15 @@ storagePoolLookupByTargetPath(virConnectPtr conn, storageDriverUnlock(); if (!pool) { - virReportError(VIR_ERR_NO_STORAGE_VOL, - _("no storage pool with matching target path '%s'"), - path); + if (STREQ(path, cleanpath)) { + virReportError(VIR_ERR_NO_STORAGE_POOL, + _("no storage pool with matching target path '%s'"), + path); + } else { + virReportError(VIR_ERR_NO_STORAGE_POOL, + _("no storage pool with matching target path '%s' (%s)"), + path, cleanpath); + } } VIR_FREE(cleanpath);