[PATCH] esx: Do not return root objects in a lookup

Martin Kletzander posted 1 patch 2 years, 3 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/09d7532e53083fc2021d32c00231fec84a83c3ee.1642888468.git.mkletzan@redhat.com
src/esx/esx_vi.c | 5 +++++
1 file changed, 5 insertions(+)
[PATCH] esx: Do not return root objects in a lookup
Posted by Martin Kletzander 2 years, 3 months ago
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 <mkletzan@redhat.com>
---
 src/esx/esx_vi.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 6f964cc470d1..80ed6199e3ac 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;
-- 
2.34.1

Re: [PATCH] esx: Do not return root objects in a lookup
Posted by Tim Wiederhake 2 years, 3 months ago
On Sat, 2022-01-22 at 22:54 +0100, Martin Kletzander wrote:
> 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 <mkletzan@redhat.com>
> ---
>  src/esx/esx_vi.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
> index 6f964cc470d1..80ed6199e3ac 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;

Reviewed-by: Tim Wiederhake <twiederh@redhat.com>