From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C311C433EF for ; Fri, 8 Oct 2021 13:12:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F9AF60F43 for ; Fri, 8 Oct 2021 13:12:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242449AbhJHNOT (ORCPT ); Fri, 8 Oct 2021 09:14:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44003 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242410AbhJHNOP (ORCPT ); Fri, 8 Oct 2021 09:14:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633698738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=WnYTeFX7lQqI8TAg+qtycd8pv7aRimkmtdXDeDpWrKI=; b=BbEw1mGeR+dE0dUQJW6Cag+q9mOD1ybagtbRtY1NeUwRalN5UcFe6Z4L/5BY3qbv8740uQ k6PLMfVJ30TgwwRI59FIufTjz3FhXKCt6LFMcwiDKVfeYlPd+KU8fUSxPL2KiorbkGWBYM q5QRf7E3XDXDd1RUtXEtQF7zIMj/uyE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-189-9mElWLOiMAuF7SaWydwe4w-1; Fri, 08 Oct 2021 09:12:07 -0400 X-MC-Unique: 9mElWLOiMAuF7SaWydwe4w-1 Received: by mail-wr1-f71.google.com with SMTP id a10-20020a5d508a000000b00160723ce588so7284573wrt.23 for ; Fri, 08 Oct 2021 06:12:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=WnYTeFX7lQqI8TAg+qtycd8pv7aRimkmtdXDeDpWrKI=; b=lO5NbRFrAl5ALxpx2xarc8KPriyxyRuhooyM7RRJgvli2Tj8MvVwWjTrRTFwUGua6M VtYwYddMuAd2AivdLB1xifS1TZDXZc7GI9hHFzrEgAq2/nwZKuFOt95AhQR0QxidNOpA 7nAE1EAAAARamcOzqVhiABpUFP7nEhcCHvvR2IFTI2JNFwBwq5jKoEn/95eh4rJCyUTh MYLix+Il7gGQN0mEUUJ7uJkRngL/5ywBTEuKaaEtKUJfqU4dmgeN4SKqWK6sUcp3ZQRA KYtonEjSj5FHltOwv17lgGhEOtMsCc/28PANPVYOhp7FRt+mkmwMV0W2WWn3hxXuX7he rKQg== X-Gm-Message-State: AOAM531oT8R/hYemMVV4NzmlVBkoxQ/3EnVTc+g1JxZwUddKh4/Rw8Uf 5SPlXLU/cI365Yb/anuD+vR+XsGEVtHQTZlqW9f06KU2FAvkjhGvUfcQWOQTVeK+tNKPYMzjp0a zRDsJmZu4zi54OuACT8fX7249 X-Received: by 2002:a05:600c:a49:: with SMTP id c9mr3367817wmq.159.1633698725747; Fri, 08 Oct 2021 06:12:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCSO/Avnl4s1uQbwWoYbdYzpDTgr0ryONsaTkgBvKCfsjZ230gSR23hW1R7JgDYoCIz7QQig== X-Received: by 2002:a05:600c:a49:: with SMTP id c9mr3367782wmq.159.1633698725546; Fri, 08 Oct 2021 06:12:05 -0700 (PDT) Received: from krava (nat-pool-brq-u.redhat.com. [213.175.37.12]) by smtp.gmail.com with ESMTPSA id k17sm2494501wrq.7.2021.10.08.06.12.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 06:12:05 -0700 (PDT) Date: Fri, 8 Oct 2021 15:12:03 +0200 From: Jiri Olsa To: James Clark Cc: acme@kernel.org, john.garry@huawei.com, ak@linux.intel.com, linux-perf-users@vger.kernel.org, Nick.Forrington@arm.com, Andrew.Kilroy@arm.com, Will Deacon , Mathieu Poirier , Leo Yan , Mark Rutland , Alexander Shishkin , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] perf tools: Make the JSON parser more conformant when in strict mode Message-ID: References: <20211007110543.564963-1-james.clark@arm.com> <20211007110543.564963-3-james.clark@arm.com> <2e14963b-cb98-f508-7067-255fdbd36bdb@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2e14963b-cb98-f508-7067-255fdbd36bdb@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 08, 2021 at 11:08:25AM +0100, James Clark wrote: > > > On 07/10/2021 18:52, Jiri Olsa wrote: > > On Thu, Oct 07, 2021 at 12:05:41PM +0100, James Clark wrote: > >> Return an error when a trailing comma is found or a new item is > >> encountered before a comma or an opening brace. This ensures that the > >> perf json files conform more closely to the spec at https://www.json.org > >> > >> Signed-off-by: James Clark > >> --- > >> tools/perf/pmu-events/jsmn.c | 42 ++++++++++++++++++++++++++++++++++-- > >> 1 file changed, 40 insertions(+), 2 deletions(-) > >> > >> diff --git a/tools/perf/pmu-events/jsmn.c b/tools/perf/pmu-events/jsmn.c > >> index 11d1fa18bfa5..8124d2d3ff0c 100644 > >> --- a/tools/perf/pmu-events/jsmn.c > >> +++ b/tools/perf/pmu-events/jsmn.c > >> @@ -176,6 +176,14 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> jsmnerr_t r; > >> int i; > >> jsmntok_t *token; > >> +#ifdef JSMN_STRICT > > > > I might have missed some discussion on this, but do we need the > > JSMN_STRICT define, if you enable it in the next patch? > > why can't we be more strict by default.. do you plan to disable > > it in future? > > I didn't plan on disabling it, I was just trying to keep to the existing style of the > jsmn project. > > I could have added the trailing comma detection by default and not inside any > #ifdef JSMN_STRICT blocks, but I would like to enable JSMN_STRICT anyway, because it > enables some additional built in checking that was already there. So I thought it > made sense to put my new strict stuff inside the existing strict option. > > One option would be to remove all (including the existing) #ifdef JSMN_STRICT blocks > and have everything strict by default. But it would be a further deviation from jsmn. ok, I think it makes sense to have JSMN_STRICT then.. thanks for explanation Acked-by: Jiri Olsa jirka > > Thanks > James > > > > > thanks, > > jirka > > > >> + /* > >> + * Keeps track of whether a new object/list/primitive is expected. New items are only > >> + * allowed after an opening brace, comma or colon. A closing brace after a comma is not > >> + * valid JSON. > >> + */ > >> + int expecting_item = 1; > >> +#endif > >> > >> for (; parser->pos < len; parser->pos++) { > >> char c; > >> @@ -185,6 +193,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> switch (c) { > >> case '{': > >> case '[': > >> +#ifdef JSMN_STRICT > >> + if (!expecting_item) > >> + return JSMN_ERROR_INVAL; > >> +#endif > >> token = jsmn_alloc_token(parser, tokens, num_tokens); > >> if (token == NULL) > >> return JSMN_ERROR_NOMEM; > >> @@ -196,6 +208,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> break; > >> case '}': > >> case ']': > >> +#ifdef JSMN_STRICT > >> + if (expecting_item) > >> + return JSMN_ERROR_INVAL; > >> +#endif > >> type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY); > >> for (i = parser->toknext - 1; i >= 0; i--) { > >> token = &tokens[i]; > >> @@ -219,6 +235,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> } > >> break; > >> case '\"': > >> +#ifdef JSMN_STRICT > >> + if (!expecting_item) > >> + return JSMN_ERROR_INVAL; > >> + expecting_item = 0; > >> +#endif > >> r = jsmn_parse_string(parser, js, len, tokens, > >> num_tokens); > >> if (r < 0) > >> @@ -229,11 +250,15 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> case '\t': > >> case '\r': > >> case '\n': > >> - case ':': > >> - case ',': > >> case ' ': > >> break; > >> #ifdef JSMN_STRICT > >> + case ':': > >> + case ',': > >> + if (expecting_item) > >> + return JSMN_ERROR_INVAL; > >> + expecting_item = 1; > >> + break; > >> /* > >> * In strict mode primitives are: > >> * numbers and booleans. > >> @@ -253,6 +278,9 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> case 'f': > >> case 'n': > >> #else > >> + case ':': > >> + case ',': > >> + break; > >> /* > >> * In non-strict mode every unquoted value > >> * is a primitive. > >> @@ -260,6 +288,12 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> /*FALL THROUGH */ > >> default: > >> #endif > >> + > >> +#ifdef JSMN_STRICT > >> + if (!expecting_item) > >> + return JSMN_ERROR_INVAL; > >> + expecting_item = 0; > >> +#endif > >> r = jsmn_parse_primitive(parser, js, len, tokens, > >> num_tokens); > >> if (r < 0) > >> @@ -282,7 +316,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> return JSMN_ERROR_PART; > >> } > >> > >> +#ifdef JSMN_STRICT > >> + return expecting_item ? JSMN_ERROR_INVAL : JSMN_SUCCESS; > >> +#else > >> return JSMN_SUCCESS; > >> +#endif > >> } > >> > >> /* > >> -- > >> 2.28.0 > >> > > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1FBBC433EF for ; Fri, 8 Oct 2021 13:14:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8A36360F43 for ; Fri, 8 Oct 2021 13:14:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8A36360F43 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Eqz7SNejGbj24STYsVcpi7XIHj3CNK00PB/hktUzb1Y=; b=hR6EI0Ey0pEJko EdM7BmdZMewBLedcQDabWHI836F+UpzPdIshuDG+y94v2Ic2I8pbVy6mT/r628t/ovmNVPTKTTrMV pHF8XcFHCT5Qxu5UzEdWcyhh1MhsHJzB85Rx/x7ZeYy3yPMCNdgPlywGAMRIXFN+9D9m/vNjjezMx eJDFJjxiAUVu40UFpOrOJuukwAcjosZX/ldpuuOOilpa8sq1SVp2EPyv37y30WV6IBktGFL3Ckw8Y bOkNuSJprqV+taBOija2eO7QcGdos7R6UfZ6EIWkkiTRtzzwn2Ue+7cGRPU4WQv3/vn5e/ne9OElP lT2DvGODAS/gPobVWscw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mYpfv-002qjw-Vr; Fri, 08 Oct 2021 13:12:36 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mYpfh-002qgN-BZ for linux-arm-kernel@lists.infradead.org; Fri, 08 Oct 2021 13:12:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633698740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=WnYTeFX7lQqI8TAg+qtycd8pv7aRimkmtdXDeDpWrKI=; b=HlRSEVOYTsKKNZjDC66E/sDGTaLO000iq05fSsql6DT7oPZFLjCCNArfvJbJehvcs0s/i6 GpLL4u3PzFDTH4eKYW+WmJmQM1tS1NdC0nEcszbNODKF1t0hZBMd6tOOqqGbo+nUoYiuD4 VuZVsfyBT3XCPr94pFTWnHHk04R8WhY= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-47-lW_9X3ZxN8un9pQ4LJNZKA-1; Fri, 08 Oct 2021 09:12:07 -0400 X-MC-Unique: lW_9X3ZxN8un9pQ4LJNZKA-1 Received: by mail-wr1-f70.google.com with SMTP id s18-20020adfbc12000000b00160b2d4d5ebso7334370wrg.7 for ; Fri, 08 Oct 2021 06:12:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=WnYTeFX7lQqI8TAg+qtycd8pv7aRimkmtdXDeDpWrKI=; b=670creFbnCOsABLtp7R1vqwbyfDzXiT+oqlBRGTNt1L/mZGh/C9DkpM6mZ+fkkJUfD V6LFs0+Om++i4WTD2VbQEcRmXv5shS0oEpE+vjWZ4ltvIrNQuuadVNWaAYNsxAjj8akR FQnA7Exes4LlOaRnmNiS5B13+XLOMeiNQHxoHp+rlbAZ7PE882u4Y38L6hn6Y4IVGCpU YNAyhALrk7MtBKgZrym/JYKIMnbtMIt2igiENRmnL314B1XjdaixXl8XSwhGU0SYhXvg hE3ztUgfFJaqfmiTZB9H12QY9caWK7nbHtOx0aw1SqORU8YNscTcpMrP776EjypyqfyW zRpw== X-Gm-Message-State: AOAM533sNucJrHbF5QUBOs4VmPTOZQKxEicS6MzkTC9d9P4N/LsHuJYu kYSgClRj4Zn90rnOe3O8P2UMbnG2uQC0HRygDTXm35bFjmUXBQPh+EbfzN8UqzW0GEntl1Of3Y5 L+oI/aiUmPKi8hAiyBnb9Z6Gp3mNLshLNn2U= X-Received: by 2002:a05:600c:a49:: with SMTP id c9mr3367812wmq.159.1633698725746; Fri, 08 Oct 2021 06:12:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCSO/Avnl4s1uQbwWoYbdYzpDTgr0ryONsaTkgBvKCfsjZ230gSR23hW1R7JgDYoCIz7QQig== X-Received: by 2002:a05:600c:a49:: with SMTP id c9mr3367782wmq.159.1633698725546; Fri, 08 Oct 2021 06:12:05 -0700 (PDT) Received: from krava (nat-pool-brq-u.redhat.com. [213.175.37.12]) by smtp.gmail.com with ESMTPSA id k17sm2494501wrq.7.2021.10.08.06.12.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 06:12:05 -0700 (PDT) Date: Fri, 8 Oct 2021 15:12:03 +0200 From: Jiri Olsa To: James Clark Cc: acme@kernel.org, john.garry@huawei.com, ak@linux.intel.com, linux-perf-users@vger.kernel.org, Nick.Forrington@arm.com, Andrew.Kilroy@arm.com, Will Deacon , Mathieu Poirier , Leo Yan , Mark Rutland , Alexander Shishkin , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] perf tools: Make the JSON parser more conformant when in strict mode Message-ID: References: <20211007110543.564963-1-james.clark@arm.com> <20211007110543.564963-3-james.clark@arm.com> <2e14963b-cb98-f508-7067-255fdbd36bdb@arm.com> MIME-Version: 1.0 In-Reply-To: <2e14963b-cb98-f508-7067-255fdbd36bdb@arm.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211008_061221_512752_F24DA644 X-CRM114-Status: GOOD ( 34.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Oct 08, 2021 at 11:08:25AM +0100, James Clark wrote: > > > On 07/10/2021 18:52, Jiri Olsa wrote: > > On Thu, Oct 07, 2021 at 12:05:41PM +0100, James Clark wrote: > >> Return an error when a trailing comma is found or a new item is > >> encountered before a comma or an opening brace. This ensures that the > >> perf json files conform more closely to the spec at https://www.json.org > >> > >> Signed-off-by: James Clark > >> --- > >> tools/perf/pmu-events/jsmn.c | 42 ++++++++++++++++++++++++++++++++++-- > >> 1 file changed, 40 insertions(+), 2 deletions(-) > >> > >> diff --git a/tools/perf/pmu-events/jsmn.c b/tools/perf/pmu-events/jsmn.c > >> index 11d1fa18bfa5..8124d2d3ff0c 100644 > >> --- a/tools/perf/pmu-events/jsmn.c > >> +++ b/tools/perf/pmu-events/jsmn.c > >> @@ -176,6 +176,14 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> jsmnerr_t r; > >> int i; > >> jsmntok_t *token; > >> +#ifdef JSMN_STRICT > > > > I might have missed some discussion on this, but do we need the > > JSMN_STRICT define, if you enable it in the next patch? > > why can't we be more strict by default.. do you plan to disable > > it in future? > > I didn't plan on disabling it, I was just trying to keep to the existing style of the > jsmn project. > > I could have added the trailing comma detection by default and not inside any > #ifdef JSMN_STRICT blocks, but I would like to enable JSMN_STRICT anyway, because it > enables some additional built in checking that was already there. So I thought it > made sense to put my new strict stuff inside the existing strict option. > > One option would be to remove all (including the existing) #ifdef JSMN_STRICT blocks > and have everything strict by default. But it would be a further deviation from jsmn. ok, I think it makes sense to have JSMN_STRICT then.. thanks for explanation Acked-by: Jiri Olsa jirka > > Thanks > James > > > > > thanks, > > jirka > > > >> + /* > >> + * Keeps track of whether a new object/list/primitive is expected. New items are only > >> + * allowed after an opening brace, comma or colon. A closing brace after a comma is not > >> + * valid JSON. > >> + */ > >> + int expecting_item = 1; > >> +#endif > >> > >> for (; parser->pos < len; parser->pos++) { > >> char c; > >> @@ -185,6 +193,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> switch (c) { > >> case '{': > >> case '[': > >> +#ifdef JSMN_STRICT > >> + if (!expecting_item) > >> + return JSMN_ERROR_INVAL; > >> +#endif > >> token = jsmn_alloc_token(parser, tokens, num_tokens); > >> if (token == NULL) > >> return JSMN_ERROR_NOMEM; > >> @@ -196,6 +208,10 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> break; > >> case '}': > >> case ']': > >> +#ifdef JSMN_STRICT > >> + if (expecting_item) > >> + return JSMN_ERROR_INVAL; > >> +#endif > >> type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY); > >> for (i = parser->toknext - 1; i >= 0; i--) { > >> token = &tokens[i]; > >> @@ -219,6 +235,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> } > >> break; > >> case '\"': > >> +#ifdef JSMN_STRICT > >> + if (!expecting_item) > >> + return JSMN_ERROR_INVAL; > >> + expecting_item = 0; > >> +#endif > >> r = jsmn_parse_string(parser, js, len, tokens, > >> num_tokens); > >> if (r < 0) > >> @@ -229,11 +250,15 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> case '\t': > >> case '\r': > >> case '\n': > >> - case ':': > >> - case ',': > >> case ' ': > >> break; > >> #ifdef JSMN_STRICT > >> + case ':': > >> + case ',': > >> + if (expecting_item) > >> + return JSMN_ERROR_INVAL; > >> + expecting_item = 1; > >> + break; > >> /* > >> * In strict mode primitives are: > >> * numbers and booleans. > >> @@ -253,6 +278,9 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> case 'f': > >> case 'n': > >> #else > >> + case ':': > >> + case ',': > >> + break; > >> /* > >> * In non-strict mode every unquoted value > >> * is a primitive. > >> @@ -260,6 +288,12 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> /*FALL THROUGH */ > >> default: > >> #endif > >> + > >> +#ifdef JSMN_STRICT > >> + if (!expecting_item) > >> + return JSMN_ERROR_INVAL; > >> + expecting_item = 0; > >> +#endif > >> r = jsmn_parse_primitive(parser, js, len, tokens, > >> num_tokens); > >> if (r < 0) > >> @@ -282,7 +316,11 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len, > >> return JSMN_ERROR_PART; > >> } > >> > >> +#ifdef JSMN_STRICT > >> + return expecting_item ? JSMN_ERROR_INVAL : JSMN_SUCCESS; > >> +#else > >> return JSMN_SUCCESS; > >> +#endif > >> } > >> > >> /* > >> -- > >> 2.28.0 > >> > > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel