]> xenbits.xensource.com Git - libvirt.git/commitdiff
esx: Fix managed object lookup with optional occurrence
authorMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 6 Sep 2011 17:05:08 +0000 (19:05 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Thu, 8 Sep 2011 08:36:48 +0000 (10:36 +0200)
Exit early if managed object is not found, instead of dereferencing
a NULL pointer and triggering a segfault.

src/esx/esx_vi.c

index 5c8d79e56c025932098dabfa2c55b6fffdbc38b3..f4033eb8e06763b88f43e9266fdfe6ab98596df8 100644 (file)
@@ -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;                                                     \
         }                                                                     \