qom: Fix ambiguous path detection when ambiguous=NULL

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.

Backports commit ebcc479eee740937e70a94a468effcf2126a572b from qemu
This commit is contained in:
Eduardo Habkost 2018-03-03 22:49:14 -05:00 committed by Lioncash
parent 1c0169842d
commit 570c064065
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -1481,15 +1481,13 @@ static Object *object_resolve_partial_path(struct uc_struct *uc, 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;
}
}
@ -1498,7 +1496,7 @@ static Object *object_resolve_partial_path(struct uc_struct *uc, Object *parent,
}
Object *object_resolve_path_type(struct uc_struct *uc, const char *path, const char *typename,
bool *ambiguous)
bool *ambiguousp)
{
Object *obj;
gchar **parts;
@ -1507,11 +1505,12 @@ Object *object_resolve_path_type(struct uc_struct *uc, const char *path, const c
assert(parts);
if (parts[0] == NULL || strcmp(parts[0], "") != 0) {
if (ambiguous) {
*ambiguous = false;
}
bool ambiguous = false;
obj = object_resolve_partial_path(uc, object_get_root(NULL), parts,
typename, ambiguous);
typename, &ambiguous);
if (ambiguousp) {
*ambiguousp = ambiguous;
}
} else {
obj = object_resolve_abs_path(uc, object_get_root(NULL), parts, typename, 1);
}