From nobody Thu Nov 6 12:11:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490026523617316.2154639562309; Mon, 20 Mar 2017 09:15:23 -0700 (PDT) Received: from localhost ([::1]:33883 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpzxq-0000p4-7n for importer@patchew.org; Mon, 20 Mar 2017 12:15:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpzwM-0000Du-Lj for qemu-devel@nongnu.org; Mon, 20 Mar 2017 12:13:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cpzwJ-0004l7-FL for qemu-devel@nongnu.org; Mon, 20 Mar 2017 12:13:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59872) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cpzwJ-0004kl-9S for qemu-devel@nongnu.org; Mon, 20 Mar 2017 12:13:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 621A53B71F; Mon, 20 Mar 2017 16:13:47 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 282DB785D4; Mon, 20 Mar 2017 16:13:47 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9A2AD113864A; Mon, 20 Mar 2017 17:13:44 +0100 (CET) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 621A53B71F Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 621A53B71F From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 20 Mar 2017 17:13:43 +0100 Message-Id: <1490026424-11330-2-git-send-email-armbru@redhat.com> In-Reply-To: <1490026424-11330-1-git-send-email-armbru@redhat.com> References: <1490026424-11330-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 20 Mar 2017 16:13:47 +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] [PATCH for-2.9 1/2] qapi: Fix string input visitor regression for empty lists 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: imammedo@redhat.com, ehabkost@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Visiting a list when input is the empty string should result in an empty list, not an error. Noticed when commit 3d089ce belatedly added tests, but simply accepted as weird then. It's actually a regression: broken in commit 74f24cb, v2.7.0. Fix it, and throw in another test case for empty string. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Michael Roth --- qapi/string-input-visitor.c | 4 ++++ tests/test-string-input-visitor.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index 806b01ae..c089491 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -54,6 +54,10 @@ static int parse_str(StringInputVisitor *siv, const char= *name, Error **errp) return 0; } =20 + if (!*str) { + return 0; + } + do { errno =3D 0; start =3D strtoll(str, &endptr, 0); diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-vi= sitor.c index 6db850b..79313a7 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -63,6 +63,11 @@ static void test_visitor_in_int(TestInputVisitorData *da= ta, =20 visit_type_int(v, NULL, &res, &err); error_free_or_abort(&err); + + v =3D visitor_input_test_init(data, ""); + + visit_type_int(v, NULL, &res, &err); + error_free_or_abort(&err); } =20 static void check_ilist(Visitor *v, int64_t *expected, size_t n) @@ -140,11 +145,11 @@ static void test_visitor_in_intList(TestInputVisitorD= ata *data, v =3D visitor_input_test_init(data, "18446744073709551615"); check_ulist(v, expect4, ARRAY_SIZE(expect4)); =20 - /* Empty list is invalid (weird) */ + /* Empty list */ =20 v =3D visitor_input_test_init(data, ""); - visit_type_int64List(v, NULL, &res, &err); - error_free_or_abort(&err); + visit_type_int64List(v, NULL, &res, &error_abort); + g_assert(!res); =20 /* Not a list */ =20 --=20 2.7.4 From nobody Thu Nov 6 12:11:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490026475439881.4153889606716; Mon, 20 Mar 2017 09:14:35 -0700 (PDT) Received: from localhost ([::1]:33880 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpzx3-0000GK-WA for importer@patchew.org; Mon, 20 Mar 2017 12:14:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpzwM-0000Dp-L2 for qemu-devel@nongnu.org; Mon, 20 Mar 2017 12:13:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cpzwJ-0004lI-IR for qemu-devel@nongnu.org; Mon, 20 Mar 2017 12:13:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54858) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cpzwJ-0004kp-AK for qemu-devel@nongnu.org; Mon, 20 Mar 2017 12:13:47 -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 63AED80462; Mon, 20 Mar 2017 16:13:47 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2966AE4B82; Mon, 20 Mar 2017 16:13:47 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9C4B6113864D; Mon, 20 Mar 2017 17:13:44 +0100 (CET) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 63AED80462 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 63AED80462 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 20 Mar 2017 17:13:44 +0100 Message-Id: <1490026424-11330-3-git-send-email-armbru@redhat.com> In-Reply-To: <1490026424-11330-1-git-send-email-armbru@redhat.com> References: <1490026424-11330-1-git-send-email-armbru@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.28]); Mon, 20 Mar 2017 16:13:47 +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] [PATCH for-2.9 2/2] Revert "hostmem: fix QEMU crash by 'info memdev'" 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: Xiao Guangrong , ehabkost@redhat.com, mdroth@linux.vnet.ibm.com, Paolo Bonzini , imammedo@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This reverts commit 1454d33f0507cb54d62ed80f494884157c9e7130. The string input visitor regression fixed in the previous commit made visit_type_uint16List() fail on empty input. query_memdev() calls it via object_property_get_uint16List(). Because it doesn't expect it to fail, it passes &error_abort, and duly crashes. Commit 1454d33 "fixes" this crash by making host_memory_backend_get_host_nodes() return a list containing just MAX_NODES instead of the empty list. Papers over the regression, and leads to bogus "info memdev" output, as shown below; revert. I suspect that if we had bisected the crash back then, we would have found and fixed the actual bug instead of papering over it. To reproduce, run HMP command "info memdev" with $ qemu-system-x86_64 --nodefaults -S -display none -monitor stdio -obje= ct memory-backend-ram,id=3Dmem1,size=3D4k With this commit, "info memdev" prints memory backend: mem1 size: 4096 merge: true dump: true prealloc: false policy: default host nodes: exactly like before commit 74f24cb. Between commit 1454d33 and this commit, it prints memory backend: mem1 size: 4096 merge: true dump: true prealloc: false policy: default host nodes: 128 The last line is bogus. Between commit 74f24cb and 1454d33, it crashes like this: Unexpected error in parse_str() at /work/armbru/tmp/qemu/qapi/string-in= put-visitor.c:126: Parameter 'null' expects an int64 value or range Aborted (core dumped) Cc: Xiao Guangrong Cc: Paolo Bonzini Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Michael Roth --- backends/hostmem.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/backends/hostmem.c b/backends/hostmem.c index 162c218..89feb9e 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -64,14 +64,6 @@ out: error_propagate(errp, local_err); } =20 -static uint16List **host_memory_append_node(uint16List **node, - unsigned long value) -{ - *node =3D g_malloc0(sizeof(**node)); - (*node)->value =3D value; - return &(*node)->next; -} - static void host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *na= me, void *opaque, Error **errp) @@ -82,23 +74,25 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor= *v, const char *name, unsigned long value; =20 value =3D find_first_bit(backend->host_nodes, MAX_NODES); - - node =3D host_memory_append_node(node, value); - if (value =3D=3D MAX_NODES) { - goto out; + return; } =20 + *node =3D g_malloc0(sizeof(**node)); + (*node)->value =3D value; + node =3D &(*node)->next; + do { value =3D find_next_bit(backend->host_nodes, MAX_NODES, value + 1); if (value =3D=3D MAX_NODES) { break; } =20 - node =3D host_memory_append_node(node, value); + *node =3D g_malloc0(sizeof(**node)); + (*node)->value =3D value; + node =3D &(*node)->next; } while (true); =20 -out: visit_type_uint16List(v, name, &host_nodes, errp); } =20 --=20 2.7.4