From patchwork Mon Jul 17 18:50:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 789678 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xBCBy4FvXz9t1Z for ; Tue, 18 Jul 2017 04:54:34 +1000 (AEST) Received: from localhost ([::1]:52028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXBA6-0005tW-Vu for incoming@patchwork.ozlabs.org; Mon, 17 Jul 2017 14:54:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXB6u-0003Li-8U for qemu-devel@nongnu.org; Mon, 17 Jul 2017 14:51:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXB6p-0003gm-4v for qemu-devel@nongnu.org; Mon, 17 Jul 2017 14:51:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40382) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXB6o-0003fv-Rt for qemu-devel@nongnu.org; Mon, 17 Jul 2017 14:51:07 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCEF32F86D1; Mon, 17 Jul 2017 18:51:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BCEF32F86D1 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BCEF32F86D1 Received: from localhost (ovpn-116-61.gru2.redhat.com [10.97.116.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50A0A5D6A2; Mon, 17 Jul 2017 18:51:05 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell Date: Mon, 17 Jul 2017 15:50:42 -0300 Message-Id: <20170717185051.18740-7-ehabkost@redhat.com> In-Reply-To: <20170717185051.18740-1-ehabkost@redhat.com> References: <20170717185051.18740-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 17 Jul 2017 18:51:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 06/15] qom: Fix ambiguous path detection when ambiguous=NULL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Cc: Mark Cave-Ayland Signed-off-by: Eduardo Habkost Message-Id: <20170707213052.13087-3-ehabkost@redhat.com> Signed-off-by: Eduardo Habkost --- 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);