From nobody Wed Nov 5 10:43:14 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1533730593977193.92764153719725; Wed, 8 Aug 2018 05:16:33 -0700 (PDT) Received: from localhost ([::1]:43226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnNOC-00013l-Nz for importer@patchew.org; Wed, 08 Aug 2018 08:16:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52574) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnNBq-0006js-2l for qemu-devel@nongnu.org; Wed, 08 Aug 2018 08:03:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnNBl-000070-9A for qemu-devel@nongnu.org; Wed, 08 Aug 2018 08:03:46 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51102 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fnNBk-0008Vo-Ox for qemu-devel@nongnu.org; Wed, 08 Aug 2018 08:03:40 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BDB87402382B; Wed, 8 Aug 2018 12:03:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-62.ams2.redhat.com [10.36.117.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 770E51C716; Wed, 8 Aug 2018 12:03:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D435011386DB; Wed, 8 Aug 2018 14:03:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 8 Aug 2018 14:03:17 +0200 Message-Id: <20180808120334.10970-40-armbru@redhat.com> In-Reply-To: <20180808120334.10970-1-armbru@redhat.com> References: <20180808120334.10970-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 08 Aug 2018 12:03:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 08 Aug 2018 12:03:39 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 39/56] json: Leave rejecting invalid interpolation to parser 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Both lexer and parser reject invalid interpolation specifications. The parser's check is useless. The lexer ends the token right after the first bad character. This tends to lead to suboptimal error reporting. For instance, input [ %11d ] produces the tokens JSON_LSQUARE [ JSON_ERROR %1 JSON_INTEGER 1 JSON_KEYWORD d JSON_RSQUARE ] The parser then yields an error, an object and two more errors: error: Invalid JSON syntax object: 1 error: JSON parse error, invalid keyword error: JSON parse error, expecting value Change the lexer to accept [A-Za-z0-9]*[duipsf]. It now produces JSON_LSQUARE [ JSON_INTERPOLATION %11d JSON_RSQUARE ] and the parser reports just JSON parse error, invalid interpolation '%11d' Signed-off-by: Markus Armbruster --- qobject/json-lexer.c | 52 +++++++++---------------------------------- qobject/json-parser.c | 1 + 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c index 0ea1eae4aa..7a82aab88b 100644 --- a/qobject/json-lexer.c +++ b/qobject/json-lexer.c @@ -93,7 +93,8 @@ * (apostrophe) instead of %x22 (quotation mark), and can't contain * unescaped apostrophe, but can contain unescaped quotation mark. * - Interpolation: - * interpolation =3D %((l|ll|I64)[du]|[ipsf]) + * The lexer accepts [A-Za-z0-9]*, and leaves rejecting invalid ones + * to the parser. * * Note: * - Input must be encoded in modified UTF-8. @@ -116,11 +117,6 @@ enum json_lexer_state { IN_NEG_NONZERO_NUMBER, IN_KEYWORD, IN_INTERPOL, - IN_INTERPOL_L, - IN_INTERPOL_LL, - IN_INTERPOL_I, - IN_INTERPOL_I6, - IN_INTERPOL_I64, IN_WHITESPACE, IN_START_INTERPOL, IN_START, @@ -222,42 +218,6 @@ static const uint8_t json_lexer[][256] =3D { ['\n'] =3D IN_WHITESPACE, }, =20 - /* interpolation */ - [IN_INTERPOL_LL] =3D { - ['d'] =3D JSON_INTERPOL, - ['u'] =3D JSON_INTERPOL, - }, - - [IN_INTERPOL_L] =3D { - ['d'] =3D JSON_INTERPOL, - ['l'] =3D IN_INTERPOL_LL, - ['u'] =3D JSON_INTERPOL, - }, - - [IN_INTERPOL_I64] =3D { - ['d'] =3D JSON_INTERPOL, - ['u'] =3D JSON_INTERPOL, - }, - - [IN_INTERPOL_I6] =3D { - ['4'] =3D IN_INTERPOL_I64, - }, - - [IN_INTERPOL_I] =3D { - ['6'] =3D IN_INTERPOL_I6, - }, - - [IN_INTERPOL] =3D { - ['d'] =3D JSON_INTERPOL, - ['i'] =3D JSON_INTERPOL, - ['p'] =3D JSON_INTERPOL, - ['s'] =3D JSON_INTERPOL, - ['u'] =3D JSON_INTERPOL, - ['f'] =3D JSON_INTERPOL, - ['l'] =3D IN_INTERPOL_L, - ['I'] =3D IN_INTERPOL_I, - }, - /* top level rule */ [IN_START] =3D { ['"'] =3D IN_DQ_STRING, @@ -278,6 +238,14 @@ static const uint8_t json_lexer[][256] =3D { ['\n'] =3D IN_WHITESPACE, }, =20 + /* interpolation */ + [IN_INTERPOL] =3D { + TERMINAL(JSON_INTERPOL), + ['A' ... 'Z'] =3D IN_INTERPOL, + ['a' ... 'z'] =3D IN_INTERPOL, + ['0' ... '9'] =3D IN_INTERPOL, + }, + [IN_START_INTERPOL] =3D { ['"'] =3D IN_DQ_STRING, ['\''] =3D IN_SQ_STRING, diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 848d469b2a..bd137399e5 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -448,6 +448,7 @@ static QObject *parse_interpolation(JSONParserContext *= ctxt, va_list *ap) } else if (!strcmp(token->str, "%f")) { return QOBJECT(qnum_from_double(va_arg(*ap, double))); } + parse_error(ctxt, token, "invalid interpolation '%s'", token->str); return NULL; } =20 --=20 2.17.1