From nobody Mon Feb 9 11:32:11 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 1488317795302353.3929920830451; Tue, 28 Feb 2017 13:36:35 -0800 (PST) Received: from localhost ([::1]:37095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cipRg-0006V0-Us for importer@patchew.org; Tue, 28 Feb 2017 16:36:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cipIs-0007XZ-8g for qemu-devel@nongnu.org; Tue, 28 Feb 2017 16:27:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cipIp-0000xw-Qb for qemu-devel@nongnu.org; Tue, 28 Feb 2017 16:27:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52836) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cipIk-0000rY-K3; Tue, 28 Feb 2017 16:27:18 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B69983B731; Tue, 28 Feb 2017 21:27:18 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SLRGCW025945 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 28 Feb 2017 16:27:18 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 72C0B1138619; Tue, 28 Feb 2017 22:27:10 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 28 Feb 2017 22:27:05 +0100 Message-Id: <1488317230-26248-20-git-send-email-armbru@redhat.com> In-Reply-To: <1488317230-26248-1-git-send-email-armbru@redhat.com> References: <1488317230-26248-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 28 Feb 2017 21:27:18 +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 v2 19/24] keyval: Restrict key components to valid QAPI names 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: kwolf@redhat.com, pkrempa@redhat.com, mdroth@linux.vnet.ibm.com, qemu-block@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" Restricting the key components to something sane leaves us room for evolving key syntax. Since they will be commonly used as QAPI member names by the QObject input visitor, we can just as well borrow the QAPI naming rules here. Signed-off-by: Markus Armbruster Reviewed-by: Kevin Wolf --- tests/test-keyval.c | 10 ++++++++++ util/keyval.c | 12 ++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/test-keyval.c b/tests/test-keyval.c index 1c2aeea..efe27cd 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -41,6 +41,11 @@ static void test_keyval_parse(void) error_free_or_abort(&err); g_assert(!qdict); =20 + /* Invalid non-empty key (qemu_opts_parse() doesn't care) */ + qdict =3D keyval_parse("7up=3Dval", NULL, &err); + error_free_or_abort(&err); + g_assert(!qdict); + /* Overlong key */ memset(long_key, 'a', 127); long_key[127] =3D 'z'; @@ -73,6 +78,11 @@ static void test_keyval_parse(void) QDECREF(qdict); g_free(params); =20 + /* Crap after valid key */ + qdict =3D keyval_parse("key[0]=3Dval", NULL, &err); + error_free_or_abort(&err); + g_assert(!qdict); + /* Multiple keys, last one wins */ qdict =3D keyval_parse("a=3D1,b=3D2,,x,a=3D3", NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), =3D=3D, 2); diff --git a/util/keyval.c b/util/keyval.c index 990126f..29a6368 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -34,6 +34,8 @@ * doesn't have one, because R.a must be an object to satisfy a.b=3D1 * and a string to satisfy a=3D2. * + * Key-fragments must be valid QAPI names. + * * The length of any key-fragment must be between 1 and 127. * * Design flaw: there is no way to denote an empty non-root object. @@ -51,12 +53,12 @@ * where no-key is syntactic sugar for implied-key=3Dval-no-key. * * TODO support lists - * TODO support key-fragment with __RFQDN_ prefix (downstream extensions) */ =20 #include "qemu/osdep.h" #include "qapi/error.h" #include "qapi/qmp/qstring.h" +#include "qapi/util.h" #include "qemu/option.h" =20 /* @@ -118,6 +120,7 @@ static const char *keyval_parse_one(QDict *qdict, const= char *params, size_t len; char key_in_cur[128]; QDict *cur; + int ret; QObject *next; QString *val; =20 @@ -137,9 +140,10 @@ static const char *keyval_parse_one(QDict *qdict, cons= t char *params, cur =3D qdict; s =3D key; for (;;) { - for (len =3D 0; s + len < key_end && s[len] !=3D '.'; len++) { - } - if (!len) { + ret =3D parse_qapi_name(s, false); + len =3D ret < 0 ? 0 : ret; + assert(s + len <=3D key_end); + if (!len || (s + len < key_end && s[len] !=3D '.')) { assert(key !=3D implied_key); error_setg(errp, "Invalid parameter '%.*s'", (int)(key_end - key), key); --=20 2.7.4