From patchwork Wed May 30 07:17:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 10437757 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7F357602CC for ; Wed, 30 May 2018 07:19:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 680DD2888B for ; Wed, 30 May 2018 07:19:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BD7D28891; Wed, 30 May 2018 07:19:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DB0322888B for ; Wed, 30 May 2018 07:19:22 +0000 (UTC) Received: from localhost ([::1]:36654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNvOD-00071I-QU for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 May 2018 03:19:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNvN0-00068U-PV for qemu-devel@nongnu.org; Wed, 30 May 2018 03:18:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNvMx-0005Qh-MI for qemu-devel@nongnu.org; Wed, 30 May 2018 03:18:06 -0400 Received: from [107.173.13.209] (port=51644 helo=ozlabs.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNvMx-0005Qb-FR for qemu-devel@nongnu.org; Wed, 30 May 2018 03:18:03 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 03706AE801DC; Wed, 30 May 2018 03:16:57 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Wed, 30 May 2018 17:17:56 +1000 Message-Id: <20180530071757.9112-2-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180530071757.9112-1-aik@ozlabs.ru> References: <20180530071757.9112-1-aik@ozlabs.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 107.173.13.209 Subject: [Qemu-devel] [PATCH qemu v3 1/2] object: Handle objects with no parents 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: Alexey Kardashevskiy , Paolo Bonzini , "Dr. David Alan Gilbert" , Markus Armbruster Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP At the moment object_get_canonical_path() crashes if the object or one of its parents does not have a parent, for example, a KVM accelerator object. This adds a check for obj!=NULL in a loop to prevent the crash. In order not to return a wrong path, this checks for currently resolved partial path and does not add a leading slash to tell the reader that the path is partial as the owner object is detached. Signed-off-by: Alexey Kardashevskiy --- I have not tested the case with obj==NULL and path!=NULL as this is for objects which have parents which are not attached to the root and we do not have such objects in current QEMU afaict but I kept it just in case. --- Changes: v3: * do not check for obj->parent * return NULL or incomplete path depending on the situation --- qom/object.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/qom/object.c b/qom/object.c index 0fc9720..05138ba 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1669,7 +1669,7 @@ gchar *object_get_canonical_path(Object *obj) Object *root = object_get_root(); char *newpath, *path = NULL; - while (obj != root) { + while (obj && obj != root) { char *component = object_get_canonical_path_component(obj); if (path) { @@ -1684,7 +1684,13 @@ gchar *object_get_canonical_path(Object *obj) obj = obj->parent; } - newpath = g_strdup_printf("/%s", path ? path : ""); + if (obj && path) { + newpath = g_strdup_printf("/%s", path); + } else if (path) { + newpath = g_strdup(path); + } else { + newpath = NULL; + } g_free(path); return newpath;