[PATCH] esx: Fix managed object lookup with optional occurrence

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Exit early if managed object is not found, instead of dereferencing
a NULL pointer and triggering a segfault.
---
 src/esx/esx_vi.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 5c8d79e..f4033eb 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -3964,7 +3964,7 @@ esxVI_ProductVersionToDefaultVirtualHWVersion(esxVI_ProductVersion productVersio
 
 
 #define ESX_VI__TEMPLATE__LOOKUP(_type, _complete_properties,                 \
-                                         _cast_from_anytype)                  \
+                                 _cast_from_anytype)                          \
     int                                                                       \
     esxVI_Lookup##_type(esxVI_Context *ctx, const char* name /* optional */,  \
                         esxVI_ManagedObjectReference *root,                   \
@@ -3999,6 +3999,12 @@ esxVI_ProductVersionToDefaultVirtualHWVersion(esxVI_ProductVersion productVersio
             goto cleanup;                                                     \
         }                                                                     \
                                                                               \
+        if (objectContent == NULL) {                                          \
+            /* not found, exit early */                                       \
+            result = 0;                                                       \
+            goto cleanup;                                                     \
+        }                                                                     \
+                                                                              \
         if (esxVI_##_type##_Alloc(ptrptr) < 0) {                              \
             goto cleanup;                                                     \
         }                                                                     \
-- 
1.7.4.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]