[PATCH] esx: Avoid corner case where esxUtil_ParseDatastorePath could be called with NULL 'datastorePath'

Peter Krempa via Devel posted 1 patch 3 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/e7fc4993f91281118fa60bc8a4f9e23189da1ec5.1748855006.git.pkrempa@redhat.com
src/esx/esx_storage_backend_vmfs.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] esx: Avoid corner case where esxUtil_ParseDatastorePath could be called with NULL 'datastorePath'
Posted by Peter Krempa via Devel 3 months, 1 week ago
From: Peter Krempa <pkrempa@redhat.com>

The generated code which parses the data from XML in
esxVI_LookupDatastoreContentByDatastoreName can fill the 'folderPath'
property with NULL if it were missing from the input XML. While this is
not likely when talking to esx it is a possible outcome. Skipp NULL
results.

All other code paths already ensure that the function is not called with
NULL.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/776
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/esx/esx_storage_backend_vmfs.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c
index 145aff0c9c..8e13201fe2 100644
--- a/src/esx/esx_storage_backend_vmfs.c
+++ b/src/esx/esx_storage_backend_vmfs.c
@@ -616,6 +616,9 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names,
          searchResults = searchResults->_next) {
         g_autofree char *directoryAndFileName = NULL;

+        if (!searchResults->folderPath)
+            continue;
+
         if (esxUtil_ParseDatastorePath(searchResults->folderPath, NULL, NULL,
                                        &directoryAndFileName) < 0) {
             goto cleanup;
@@ -759,6 +762,9 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
              searchResults = searchResults->_next) {
             g_autofree char *directoryAndFileName = NULL;

+            if (searchResults->folderPath)
+                continue;
+
             if (esxUtil_ParseDatastorePath(searchResults->folderPath, NULL,
                                            NULL, &directoryAndFileName) < 0) {
                 goto cleanup;
-- 
2.49.0
Re: [PATCH] esx: Avoid corner case where esxUtil_ParseDatastorePath could be called with NULL 'datastorePath'
Posted by Pavel Hrdina via Devel 3 months, 1 week ago
On Mon, Jun 02, 2025 at 11:03:26AM +0200, Peter Krempa via Devel wrote:
> From: Peter Krempa <pkrempa@redhat.com>
> 
> The generated code which parses the data from XML in
> esxVI_LookupDatastoreContentByDatastoreName can fill the 'folderPath'
> property with NULL if it were missing from the input XML. While this is
> not likely when talking to esx it is a possible outcome. Skipp NULL

s/Skipp/Skip/

> results.
> 
> All other code paths already ensure that the function is not called with
> NULL.
> 
> Closes: https://gitlab.com/libvirt/libvirt/-/issues/776
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/esx/esx_storage_backend_vmfs.c | 6 ++++++
>  1 file changed, 6 insertions(+)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>