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 <[email protected]>
Cc: Mark Cave-Ayland <[email protected]>
Signed-off-by: Eduardo Habkost <[email protected]>
Message-Id: <
20170707213052[email protected]>
Signed-off-by: Eduardo Habkost <[email protected]>
typename, ambiguous);
if (found) {
if (obj) {
- if (ambiguous) {
- *ambiguous = true;
- }
+ *ambiguous = true;
return NULL;
}
obj = found;
}
- if (ambiguous && *ambiguous) {
+ if (*ambiguous) {
return NULL;
}
}
}
Object *object_resolve_path_type(const char *path, const char *typename,
- bool *ambiguous)
+ bool *ambiguousp)
{
Object *obj;
gchar **parts;
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);
}
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);