From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 07016A00C3; Fri, 17 Jun 2022 19:05:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E94D14280E; Fri, 17 Jun 2022 19:05:18 +0200 (CEST) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mails.dpdk.org (Postfix) with ESMTP id 7B359415D7 for ; Fri, 17 Jun 2022 19:05:18 +0200 (CEST) Received: by mail-pl1-f182.google.com with SMTP id d5so4362286plo.12 for ; Fri, 17 Jun 2022 10:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AFG0aqHYrXHsuSNRchKV+zU5Fswg24FSb62PqQgg6Tk=; b=Hcgp1PP6KBmRQ2x9ArlXWzXIPTXUlpnG8SqVnaokGqgm4yX8aVEltXtaEtIIhcr1hU Lhs7PloAbj4Tf2b6seipRpV42+lsIeZBx1nYMDVoIivzLs2IR8Oe/pe38vg/Sz5GAPc1 ypXbxiYx/dYW65WlglOKLCGjNVywDT5+FOdK2byhiIOq6Ej6VS+8+QBp2xorlUo35YL8 5O36LJAdbEYAl/ZI2YUPoqYxBgJxAuklK3zDaEmhF62zuejWwD3wsfFRkXKodBGj24/K +G0PX4nZlmRS8Nfd+aHavEvOQZjk9VT7qWMB3S10SL7RCPrKxK5OyjpZ+UBcW0V/cRTF KNHw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=AFG0aqHYrXHsuSNRchKV+zU5Fswg24FSb62PqQgg6Tk=; b=8J4raUPl6fAudn8budIRNvVP07erUwla8fbiDAPsm5fnKPiJ0nHMRRfbvKpUhujUSZ c8Yd8pF5DWDfFQJi8XKcdTuPzLgkpBLSHLNohgfYoxi6VfNlze0c1XnWw7xMcNDAFZ0L EU4PsciN07ImYK6NK0wJ4vv0RNTYOgrIDRdEm2MUsN3ZO60R7y1/WcNjsVx421uyyiSW Fvzkfe4BrPkz0WJYq8kUMmtxYhG+Z2A8SWiJAP62+wtWEh5ZhDzZQfd3f4WujhOjQFdX fVqvtMk/d4Lo0KYg1Yv91/v6bguiWFtJFasLCMgyzANVMs/w8NuictCK8M2a/cyTerhJ rmng== X-Gm-Message-State: AJIora/+BHufcstNMg2kXlyZJ19oWwCsnLPs+N+N74wDf16LuOS930o4 LOsw9JPKnXU9ILU2PHwEmkDFuA== X-Google-Smtp-Source: AGRyM1vOSYRzvqohMoLDEzo9Dn/24p4cA6jL4HU4rKoWWAyOnYtdxj+XN8B3bxqAwRpOlpZ99Ud7XQ== X-Received: by 2002:a17:90a:c402:b0:1e6:8254:3478 with SMTP id i2-20020a17090ac40200b001e682543478mr11761810pjt.101.1655485517717; Fri, 17 Jun 2022 10:05:17 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id u22-20020a62d456000000b0051c70fd5263sm3954601pfl.169.2022.06.17.10.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 10:05:17 -0700 (PDT) Date: Fri, 17 Jun 2022 10:05:14 -0700 From: Stephen Hemminger To: Bruce Richardson Cc: Morten =?UTF-8?B?QnLDuHJ1cA==?= , Chengwen Feng , thomas@monjalon.net, ferruh.yigit@xilinx.com, kevin.laatz@intel.com, andrew.rybchenko@oktetlabs.ru, jerinj@marvell.com, sachin.saxena@oss.nxp.com, hemant.agrawal@nxp.com, dev@dpdk.org Subject: Re: [PATCH v2 1/5] telemetry: escape special char when tel string Message-ID: <20220617100514.5a2df62c@hermes.local> In-Reply-To: References: <20220615073915.14041-1-fengchengwen@huawei.com> <20220617094624.17578-1-fengchengwen@huawei.com> <20220617094624.17578-2-fengchengwen@huawei.com> <98CBD80474FA8B44BF855DF32C47DC35D8713C@smartserver.smartshare.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Fri, 17 Jun 2022 12:25:04 +0100 Bruce Richardson wrote: > On Fri, Jun 17, 2022 at 01:16:08PM +0200, Morten Br=C3=B8rup wrote: > > > From: Chengwen Feng [mailto:fengchengwen@huawei.com] > > > Sent: Friday, 17 June 2022 11.46 > > >=20 > > > This patch supports escape special characters (including: \",\\,/,\b, > > > /f,/n,/r,/t) when telemetry string. > > > This patch is used to support telemetry xxx-dump commands which the > > > string may include special characters. > > >=20 > > > Signed-off-by: Chengwen Feng > > > --- > > > lib/telemetry/telemetry.c | 96 +++++++++++++++++++++++++++++++++++++= -- > > > 1 file changed, 93 insertions(+), 3 deletions(-) > > >=20 > > > diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c > > > index c6fd03a5ab..0f762f633e 100644 > > > --- a/lib/telemetry/telemetry.c > > > +++ b/lib/telemetry/telemetry.c > > > @@ -215,6 +215,94 @@ container_to_json(const struct rte_tel_data *d, > > > char *out_buf, size_t buf_len) > > > return used; > > > } > > >=20 > > > +static bool > > > +json_is_special_char(char ch) > > > +{ > > > + static unsigned char is_spec[256] =3D { 0 }; > > > + static bool init_once; > > > + > > > + if (!init_once) { > > > + is_spec['\"'] =3D 1; > > > + is_spec['\\'] =3D 1; > > > + is_spec['/'] =3D 1; > > > + is_spec['\b'] =3D 1; > > > + is_spec['\f'] =3D 1; > > > + is_spec['\n'] =3D 1; > > > + is_spec['\r'] =3D 1; > > > + is_spec['\t'] =3D 1; > > > + init_once =3D true; > > > + } > > > + > > > + return (bool)is_spec[(unsigned char)ch]; > > > +} =20 >=20 > According to the json spec at [1], the characters that need to be escaped > are: > a) any characters <0x20 > b) inverted commas/quote character \" > c) the "reverse solidus character", better known to you and I as the > back-slash. >=20 > Therefore, I think this table generation could be simplified, but also > expanded using this. For completeness we should also see about handling a= ll > control characters if they are encountered. >=20 > [1] https://www.rfc-editor.org/rfc/rfc8259.txt >=20 > /Bruce Since it is trivial could be initializer? static const uint8_t is_spec[256] =3D { [0 ... 0x20] =3D 1, ['\"' ] =3D 1, ['\\' ] =3D 1, ['/'] =3D 1, etc Or we could change the telemetry API to disallow control characters?