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 C88BEA00C3; Fri, 17 Jun 2022 18:47:12 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 92DB5415D7; Fri, 17 Jun 2022 18:47:12 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id 82C7140F19 for ; Fri, 17 Jun 2022 18:47:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655484430; x=1687020430; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=7BDJkjHa+TrOTHczmDpTYmAYAloMvHBa40u6hskm3ng=; b=Ucsjlq7m4lJfuitPxzfWHQ82c169WwhEfsGawM+QjbALBEcwdqclOpzP LI7YrYwpac9v/o43Avhe6stNjyJw1YBMCLm/MBFCic4YRd2FSPHcgzifi 8os6CqRsAv7YjIOIrVpzN60f2VaiKBKre4690LaMYnem8MfLi+VHHgRh8 QwDtAtGFiBtojXHyrYUsoSo4CyVvDOGDyXIFanvBqOk55rsIe1hLMZ5rA 5WsNjrgwbAv6w2Z5+ty5POgJjyOCwTyeUMB2fQrIawj1PCf8SPpdxRz+B vmbwnVjGocPZ3Cg26ZE2iBWIlP26ZO48m0k8FVg+g3H8r5bK1aeJyFoUY g==; X-IronPort-AV: E=McAfee;i="6400,9594,10380"; a="259328806" X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="259328806" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2022 04:25:10 -0700 X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="590085856" Received: from bricha3-mobl.ger.corp.intel.com ([10.252.24.67]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 17 Jun 2022 04:25:07 -0700 Date: Fri, 17 Jun 2022 12:25:04 +0100 From: Bruce Richardson To: Morten =?iso-8859-1?Q?Br=F8rup?= Cc: 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: 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35D8713C@smartserver.smartshare.dk> 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, Jun 17, 2022 at 01:16:08PM +0200, Morten Brørup wrote: > > From: Chengwen Feng [mailto:fengchengwen@huawei.com] > > Sent: Friday, 17 June 2022 11.46 > > > > 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. > > > > Signed-off-by: Chengwen Feng > > --- > > lib/telemetry/telemetry.c | 96 +++++++++++++++++++++++++++++++++++++-- > > 1 file changed, 93 insertions(+), 3 deletions(-) > > > > 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; > > } > > > > +static bool > > +json_is_special_char(char ch) > > +{ > > + static unsigned char is_spec[256] = { 0 }; > > + static bool init_once; > > + > > + if (!init_once) { > > + is_spec['\"'] = 1; > > + is_spec['\\'] = 1; > > + is_spec['/'] = 1; > > + is_spec['\b'] = 1; > > + is_spec['\f'] = 1; > > + is_spec['\n'] = 1; > > + is_spec['\r'] = 1; > > + is_spec['\t'] = 1; > > + init_once = true; > > + } > > + > > + return (bool)is_spec[(unsigned char)ch]; > > +} 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. Therefore, I think this table generation could be simplified, but also expanded using this. For completeness we should also see about handling all control characters if they are encountered. [1] https://www.rfc-editor.org/rfc/rfc8259.txt /Bruce