From: Igor Mammedov <imammedo@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH 2/2] qom: Fix ambiguous path detection when ambiguous=NULL
Date: Mon, 10 Jul 2017 10:18:43 +0200 [thread overview]
Message-ID: <20170710101843.161d13bb@nial.brq.redhat.com> (raw)
In-Reply-To: <20170707213052.13087-3-ehabkost@redhat.com>
On Fri, 7 Jul 2017 18:30:52 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:
> object_resolve_path*() ambiguous path detection breaks when
> ambiguous==NULL and the object tree have 3 objects of the same type and
> only 2 of them are under the same parent. e.g.:
>
> /container/obj1 (TYPE_FOO)
> /container/obj2 (TYPE_FOO)
> /obj2 (TYPE_FOO)
>
> With the above tree, object_resolve_path_type("", TYPE_FOO, NULL) will
> incorrectly return /obj2, because the search inside "/container" will
> return NULL, and the match at "/obj2" won't be detected as ambiguous.
>
> Fix that by always calling object_resolve_partial_path() with a non-NULL
> ambiguous parameter.
>
> Test case included.
>
> Reported-by: Igor Mammedov <imammedo@redhat.com>
> Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> ---
> qom/object.c | 17 ++++++++---------
> tests/check-qom-proplist.c | 3 +++
> 2 files changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/qom/object.c b/qom/object.c
> index 5f6fdfa..0cdddcb 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -1712,15 +1712,13 @@ static Object *object_resolve_partial_path(Object *parent,
> typename, ambiguous);
> if (found) {
> if (obj) {
> - if (ambiguous) {
> - *ambiguous = true;
> - }
> + *ambiguous = true;
> return NULL;
> }
> obj = found;
> }
>
> - if (ambiguous && *ambiguous) {
> + if (*ambiguous) {
> return NULL;
> }
> }
> @@ -1729,7 +1727,7 @@ static Object *object_resolve_partial_path(Object *parent,
> }
>
> Object *object_resolve_path_type(const char *path, const char *typename,
> - bool *ambiguous)
> + bool *ambiguousp)
> {
> Object *obj;
> gchar **parts;
> @@ -1738,11 +1736,12 @@ Object *object_resolve_path_type(const char *path, const char *typename,
> assert(parts);
>
> if (parts[0] == NULL || strcmp(parts[0], "") != 0) {
> - if (ambiguous) {
> - *ambiguous = false;
> - }
> + bool ambiguous = false;
> obj = object_resolve_partial_path(object_get_root(), parts,
> - typename, ambiguous);
> + typename, &ambiguous);
> + if (ambiguousp) {
> + *ambiguousp = ambiguous;
> + }
> } else {
> obj = object_resolve_abs_path(object_get_root(), parts, typename, 1);
> }
> diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
> index abafbd7..381532c 100644
> --- a/tests/check-qom-proplist.c
> +++ b/tests/check-qom-proplist.c
> @@ -593,14 +593,17 @@ static void test_qom_partial_path(void)
> ambiguous = false;
> g_assert(!object_resolve_path_type("", TYPE_DUMMY, &ambiguous));
> g_assert(ambiguous);
> + g_assert(!object_resolve_path_type("", TYPE_DUMMY, NULL));
>
> ambiguous = false;
> g_assert(!object_resolve_path("obj2", &ambiguous));
> g_assert(ambiguous);
> + g_assert(!object_resolve_path("obj2", NULL));
>
> ambiguous = false;
> g_assert(object_resolve_path("obj1", &ambiguous) == obj1);
> g_assert(!ambiguous);
> + g_assert(object_resolve_path("obj1", NULL) == obj1);
>
> object_unparent(obj1);
> object_unparent(obj2a);
next prev parent reply other threads:[~2017-07-10 8:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-07 21:30 [Qemu-devel] [PATCH 0/2] qom: Fix ambiguous path detection when ambiguous=NULL Eduardo Habkost
2017-07-07 21:30 ` [Qemu-devel] [PATCH 1/2] tests: Test case for object_resolve_path*() Eduardo Habkost
2017-07-10 8:10 ` Igor Mammedov
2017-07-10 14:45 ` Eduardo Habkost
2017-07-10 14:48 ` Igor Mammedov
2017-07-10 15:33 ` [Qemu-devel] [PATCH] fixup! qom: Fix ambiguous path detection when ambiguous=NULL Eduardo Habkost
2017-07-10 16:26 ` Igor Mammedov
2017-07-07 21:30 ` [Qemu-devel] [PATCH 2/2] " Eduardo Habkost
2017-07-10 8:18 ` Igor Mammedov [this message]
2017-07-10 6:42 ` [Qemu-devel] [PATCH 0/2] " Mark Cave-Ayland
2017-07-10 18:23 ` Eduardo Habkost
2017-07-13 12:09 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170710101843.161d13bb@nial.brq.redhat.com \
--to=imammedo@redhat.com \
--cc=afaerber@suse.de \
--cc=ehabkost@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).