From: Martin Kletzander Date: Sat, 22 Jan 2022 19:29:43 +0000 (+0100) Subject: esx: Do not return root objects in a lookup X-Git-Tag: v8.1.0-rc1~323 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2e2c9797c5cc77d33da6198455c30cc28743211d;p=thirdparty%2Flibvirt.git esx: Do not return root objects in a lookup The lookups in esx_vi work a bit differently that we are used to. The filters (travelsalSpec and selectSet) choose how to look up the objects, but given a root object the lookup lists all the objects of a requested type inside it as well as the root object itself. We then go through the results and find the one which has the same name as was requested. However in a case with nested folders of a same name this could break when the first returned object in the list is the parent folder as we'd select it only based on the name. To avoid this also add a check that the candidate we are trying to pick is not exactly the same object (reference) as the root object. https://bugzilla.redhat.com/show_bug.cgi?id=1643868 Signed-off-by: Martin Kletzander Reviewed-by: Tim Wiederhake --- diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 6f964cc470..80ed6199e3 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -4973,6 +4973,11 @@ esxVI_LookupManagedObjectHelper(esxVI_Context *ctx, candidate = candidate->_next) { name_candidate = NULL; + if (candidate->obj->_type == root->_type && + g_strcmp0(candidate->obj->type, root->type) == 0 && + g_strcmp0(candidate->obj->value, root->value) == 0) + continue; + if (esxVI_GetStringValue(candidate, "name", &name_candidate, esxVI_Occurrence_RequiredItem) < 0) { goto cleanup;