From nobody Thu May 16 23:42:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550142949906670.9106637825655; Thu, 14 Feb 2019 03:15:49 -0800 (PST) Received: from localhost ([127.0.0.1]:46447 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guEzX-00024y-UR for importer@patchew.org; Thu, 14 Feb 2019 06:15:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54814) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guEtz-00051e-7i for qemu-devel@nongnu.org; Thu, 14 Feb 2019 06:09:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guEi5-0003OD-Bd for qemu-devel@nongnu.org; Thu, 14 Feb 2019 05:57:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33248) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1guEi5-0003Mi-5I for qemu-devel@nongnu.org; Thu, 14 Feb 2019 05:57:41 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 72AD8C01D33A; Thu, 14 Feb 2019 10:57:39 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DF83101960D; Thu, 14 Feb 2019 10:57:38 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Thu, 14 Feb 2019 05:57:33 -0500 Message-Id: <20190214105733.25643-1-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 14 Feb 2019 10:57:39 +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] [PATCH v2] 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: armbru@redhat.com, mdroth@linux.vnet.ibm.com, ehabkost@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" QEMU will crashes with qapi/qobject-output-visitor.c:210: qobject_output_complete: Assertion `qov= ->root && ((&qov->stack)->slh_first =3D=3D ((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 Reviewed-by: Eric Blake Reviewed-by: Stefano Garzarella --- v2: * fixup commit message to put emphasis on property instead local variable host_nodes and make explanation more hopefully more clear. (Markus Armbruster ) --- 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, =20 value =3D find_first_bit(backend->host_nodes, MAX_NODES); if (value =3D=3D MAX_NODES) { - return; + goto ret; } =20 *node =3D g_malloc0(sizeof(**node)); @@ -106,6 +106,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor= *v, const char *name, node =3D &(*node)->next; } while (true); =20 +ret: visit_type_uint16List(v, name, &host_nodes, errp); } =20 --=20 2.18.1