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 AF0D3A0032; Sat, 18 Jun 2022 05:52:31 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 49D6C40F19; Sat, 18 Jun 2022 05:52:31 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 806C440E2D for ; Sat, 18 Jun 2022 05:52:28 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LQ24q0kv7zjXMs; Sat, 18 Jun 2022 11:50:51 +0800 (CST) Received: from [127.0.0.1] (10.67.100.224) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 18 Jun 2022 11:52:25 +0800 Subject: Re: [PATCH v2 1/5] telemetry: escape special char when tel string To: Stephen Hemminger , Bruce Richardson CC: =?UTF-8?Q?Morten_Br=c3=b8rup?= , , , , , , , , References: <20220615073915.14041-1-fengchengwen@huawei.com> <20220617094624.17578-1-fengchengwen@huawei.com> <20220617094624.17578-2-fengchengwen@huawei.com> <98CBD80474FA8B44BF855DF32C47DC35D8713C@smartserver.smartshare.dk> <20220617100514.5a2df62c@hermes.local> From: fengchengwen Message-ID: <507d1942-868b-4e60-6921-6b420190e5de@huawei.com> Date: Sat, 18 Jun 2022 11:52:25 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20220617100514.5a2df62c@hermes.local> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.100.224] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected 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 2022/6/18 1:05, Stephen Hemminger wrote: > On Fri, 17 Jun 2022 12:25:04 +0100 > Bruce Richardson wrote: > >> 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 > > Since it is trivial could be initializer? > > static const uint8_t is_spec[256] = { > [0 ... 0x20] = 1, > ['\"' ] = 1, > ['\\' ] = 1, > ['/'] = 1, > > etc > > Or we could change the telemetry API to disallow control characters? I was thinking about converting 0~0x20, but I don't think there's a scenario. I prefer change the telemetry API to disallow control characters, and this may not be a violation of the ABI, if yes, the dpdk-telemetry.py will returns an error. So I think we could add declaring and checking functions to make sure telemetry string do not allow control characters. > > > . >