From nobody Mon Feb 9 02:52:00 2026 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 1490205569083122.59218015355373; Wed, 22 Mar 2017 10:59:29 -0700 (PDT) Received: from localhost ([::1]:52619 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqkXf-0000rN-LX for importer@patchew.org; Wed, 22 Mar 2017 13:59:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqkNA-0007uW-Md for qemu-devel@nongnu.org; Wed, 22 Mar 2017 13:48:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqkN8-0001NU-Ob for qemu-devel@nongnu.org; Wed, 22 Mar 2017 13:48:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42932) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cqkN8-0001MK-Ac; Wed, 22 Mar 2017 13:48:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42934C05491A; Wed, 22 Mar 2017 17:48:34 +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 B4B1C18201; Wed, 22 Mar 2017 17:48:33 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3ADA01133006; Wed, 22 Mar 2017 18:48:28 +0100 (CET) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 42934C05491A Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 42934C05491A From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 22 Mar 2017 18:48:27 +0100 Message-Id: <1490204908-26567-17-git-send-email-armbru@redhat.com> In-Reply-To: <1490204908-26567-1-git-send-email-armbru@redhat.com> References: <1490204908-26567-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 22 Mar 2017 17:48:34 +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 v2 for-2.9 16/17] qom: Avoid unvisited 'id'/'qom-type' in user_creatable_add_opts 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: qemu-stable@nongnu.org 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" From: Eric Blake A regression in commit 15c2f669e caused us to silently ignore excess input to the QemuOpts visitor. Later, commit ea4641 accidentally abused that situation, by removing "qom-type" and "id" from the corresponding QDict but leaving them defined in the QemuOpts, when using the pair of containers to create a user-defined object. Note that since we are already traversing two separate items (a QDict and a QemuOpts), we are already able to flag bogus arguments, as in: $ ./x86_64-softmmu/qemu-system-x86_64 -nodefaults -nographic -qmp stdio -ob= ject memory-backend-ram,id=3Dmem1,size=3D4k,bogus=3Dhuh qemu-system-x86_64: -object memory-backend-ram,id=3Dmem1,size=3D4k,bogus=3D= huh: Property '.bogus' not found So the only real concern is that when we re-enable strict checking in the QemuOpts visitor, we do not want to start flagging the two leftover keys as unvisited. Rearrange the code to clean out the QemuOpts listing in advance, rather than removing items from the QDict. Since "qom-type" is usually an automatic implicit default, we don't have to restore it (this does mean that once instantiated, QemuOpts is not necessarily an accurate representation of the original command line - but this is not the first place to do that); however "id" has to be put back (requiring us to cast away a const). [As a side note, hmp_object_add() turns a QDict into a QemuOpts, then calls user_creatable_add_opts() which converts QemuOpts into a new QDict. There are probably a lot of wasteful conversions like this, but cleaning them up is a much bigger task than the immediate regression fix.] CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake Message-Id: <20170322144525.18964-3-eblake@redhat.com> Tested-by: Laurent Vivier Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- qom/object_interfaces.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 03a95c3..cc9a694 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -114,7 +114,7 @@ Object *user_creatable_add_opts(QemuOpts *opts, Error *= *errp) QDict *pdict; Object *obj; const char *id =3D qemu_opts_id(opts); - const char *type =3D qemu_opt_get(opts, "qom-type"); + char *type =3D qemu_opt_get_del(opts, "qom-type"); =20 if (!type) { error_setg(errp, QERR_MISSING_PARAMETER, "qom-type"); @@ -125,14 +125,15 @@ Object *user_creatable_add_opts(QemuOpts *opts, Error= **errp) return NULL; } =20 + qemu_opts_set_id(opts, NULL); pdict =3D qemu_opts_to_qdict(opts, NULL); - qdict_del(pdict, "qom-type"); - qdict_del(pdict, "id"); =20 v =3D opts_visitor_new(opts); obj =3D user_creatable_add_type(type, id, pdict, v, errp); visit_free(v); =20 + qemu_opts_set_id(opts, (char *) id); + g_free(type); QDECREF(pdict); return obj; } --=20 2.7.4