[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/15] qom: Fix ambiguous path detection when ambiguo
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PULL 06/15] qom: Fix ambiguous path detection when ambiguous=NULL |
Date: |
Mon, 17 Jul 2017 15:50:42 -0300 |
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 <address@hidden>
Cc: Mark Cave-Ayland <address@hidden>
Signed-off-by: Eduardo Habkost <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Eduardo Habkost <address@hidden>
---
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 dfdbd50..fe6e744 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 f6e7823..432b665 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(obj2b);
object_unparent(cont1);
--
2.9.4
- [Qemu-devel] [PULL 00/15] x86 and machine queue for 2.10 soft freeze, Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 01/15] device-crash-test: Fix regexp on whitelist, Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 02/15] tests: Test case for object_resolve_path*(), Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 03/15] qdev: fix the order compat and global properties are applied, Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 04/15] test-qdev-global-props: Test global property ordering, Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 07/15] fw_cfg: switch fw_cfg_find() to locate the fw_cfg device by type rather than path, Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 05/15] Revert "machine: Convert abstract typename on compat_props to subclass names", Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 08/15] fw_cfg: move qdev_init_nofail() from fw_cfg_init1() to callers, Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 06/15] qom: Fix ambiguous path detection when ambiguous=NULL,
Eduardo Habkost <=
- [Qemu-devel] [PULL 09/15] fw_cfg: move QOM type defines and fw_cfg types into fw_cfg.h, Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 10/15] i386: expose "TCGTCGTCGTCG" in the 0x40000000 CPUID leaf, Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 12/15] i386: add Skylake-Server cpu model, Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 13/15] tests: Simplify abstract-interfaces check with a helper, Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 11/15] i386: Update comment about XSAVES on Skylake-Client, Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 14/15] qmp: Include 'abstract' field on 'qom-list-types' output, Eduardo Habkost, 2017/07/17
- [Qemu-devel] [PULL 15/15] qmp: Include parent type on 'qom-list-types' output, Eduardo Habkost, 2017/07/17
- Re: [Qemu-devel] [PULL 00/15] x86 and machine queue for 2.10 soft freeze, Peter Maydell, 2017/07/18