From patchwork Wed Mar 6 18:40:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 1052470 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44F2qc0yHYz9s7T for ; Thu, 7 Mar 2019 05:49:31 +1100 (AEDT) Received: from localhost ([127.0.0.1]:37669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1bbc-0005n7-Md for incoming@patchwork.ozlabs.org; Wed, 06 Mar 2019 13:49:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1bag-0005jo-BH for qemu-devel@nongnu.org; Wed, 06 Mar 2019 13:48:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1baf-0003jn-HM for qemu-devel@nongnu.org; Wed, 06 Mar 2019 13:48:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37234) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1baf-0003hX-B2 for qemu-devel@nongnu.org; Wed, 06 Mar 2019 13:48:29 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5610B30D78B1; Wed, 6 Mar 2019 18:41:07 +0000 (UTC) Received: from localhost (ovpn-116-90.gru2.redhat.com [10.97.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB1BA38E36; Wed, 6 Mar 2019 18:41:06 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell , qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 15:40:58 -0300 Message-Id: <20190306184101.9974-3-ehabkost@redhat.com> In-Reply-To: <20190306184101.9974-1-ehabkost@redhat.com> References: <20190306184101.9974-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 06 Mar 2019 18:41:07 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/5] hostmem: fix crash when querying empty host-nodes property via QMP 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: Igor Mammedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Igor Mammedov QEMU will crashes with qapi/qobject-output-visitor.c:210: qobject_output_complete: Assertion `qov->root && ((&qov->stack)->slh_first == ((void *)0))' failed when trying to get value of not set hostmem's "host-nodes" property, HostMemoryBackend::host_nodes bitmap doesn't have any bits set in it, which leads to find_first_bit() returning MAX_NODES and consequently to an early return from host_memory_backend_get_host_nodes() without calling visitor. Fix it by calling visitor even if "host-nodes" property wasn't set before exiting from property getter to return valid empty list. Signed-off-by: Igor Mammedov Message-Id: <20190214105733.25643-1-imammedo@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Stefano Garzarella Signed-off-by: Eduardo Habkost --- backends/hostmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backends/hostmem.c b/backends/hostmem.c index 87b19d2111..04baf479a1 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -88,7 +88,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, value = find_first_bit(backend->host_nodes, MAX_NODES); if (value == MAX_NODES) { - return; + goto ret; } *node = g_malloc0(sizeof(**node)); @@ -106,6 +106,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, node = &(*node)->next; } while (true); +ret: visit_type_uint16List(v, name, &host_nodes, errp); }