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 76773A00C4; Mon, 25 Jul 2022 18:36:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 04EF442B7C; Mon, 25 Jul 2022 18:36:22 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 741D042B76 for ; Mon, 25 Jul 2022 18:36:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658766979; x=1690302979; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1nxMwCwaTD1+yMyvGrZuFIwtw1bNb4w86zM8At6BbB8=; b=RNoqdhXNIrM6lTMhx2hd7k4WBr8N2JkDopQIlNZbCgs0JX5kAV2UlujD qUM5/tPR3XtOuclxGRQBcFiMnENJjVBZWhSwy+RftfHhwR0pQYucQ4VHx oKSndNt2mFekjHv8RuKf70kBLT/AGMEzi8b+HsNEdBORSFhuwcAfVeI3D 97MxoPH9DAeYuoesnlb58dVMor4ykP52G7dXjbPOdvdRXmGHSk9+x7bRx Gye81QtvgoApOUERvahm2ydFM96NKRqLpS+JN12RlMy5d1lZrvZj4WZnq /hjhsp6PrC3WxDRkFm0G33+tFy1/XG7vy4cJ8rAPnTFsJWn0rF5uzCIbe Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10419"; a="288499095" X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="288499095" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2022 09:36:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="575121940" Received: from silpixa00401385.ir.intel.com (HELO silpixa00401385.ger.corp.intel.com.) ([10.237.223.47]) by orsmga006.jf.intel.com with ESMTP; 25 Jul 2022 09:36:17 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , Ciara Power Subject: [PATCH v2 06/13] telemetry: limit characters allowed in dictionary names Date: Mon, 25 Jul 2022 17:35:35 +0100 Message-Id: <20220725163543.875775-7-bruce.richardson@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220725163543.875775-1-bruce.richardson@intel.com> References: <20220623164245.561371-1-bruce.richardson@intel.com> <20220725163543.875775-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 To save issues with encoding the names of values in dicts, we limit the allowed names to a subset of character values. This list of allowed characters can be expanded as necessary in future. Signed-off-by: Bruce Richardson --- lib/telemetry/rte_telemetry.h | 8 ++++++++ lib/telemetry/telemetry_data.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/telemetry/rte_telemetry.h b/lib/telemetry/rte_telemetry.h index d586dd0fc1..a0d21d6b7f 100644 --- a/lib/telemetry/rte_telemetry.h +++ b/lib/telemetry/rte_telemetry.h @@ -64,6 +64,10 @@ rte_tel_data_start_array(struct rte_tel_data *d, enum rte_tel_value_type type); /** * Start a dictionary of values for returning from a callback * + * Dictionaries consist of key-values pairs to be returned, where the keys, + * or names, are strings and the values can be any of the types supported by telemetry. + * Name strings may only contain alphanumeric characters as well as '_' or '/' + * * @param d * The data structure passed to the callback * @return @@ -159,6 +163,7 @@ rte_tel_data_add_array_container(struct rte_tel_data *d, * The data structure passed to the callback * @param name * The name the value is to be stored under in the dict + * Must contain only alphanumeric characters or the symbols: '_' or '/' * @param val * The string to be stored in the dict * @return @@ -177,6 +182,7 @@ rte_tel_data_add_dict_string(struct rte_tel_data *d, const char *name, * The data structure passed to the callback * @param name * The name the value is to be stored under in the dict + * Must contain only alphanumeric characters or the symbols: '_' or '/' * @param val * The number to be stored in the dict * @return @@ -193,6 +199,7 @@ rte_tel_data_add_dict_int(struct rte_tel_data *d, const char *name, int val); * The data structure passed to the callback * @param name * The name the value is to be stored under in the dict + * Must contain only alphanumeric characters or the symbols: '_' or '/' * @param val * The number to be stored in the dict * @return @@ -212,6 +219,7 @@ rte_tel_data_add_dict_u64(struct rte_tel_data *d, * The data structure passed to the callback * @param name * The name the value is to be stored under in the dict. + * Must contain only alphanumeric characters or the symbols: '_' or '/' * @param val * The pointer to the container to be stored in the dict. * @param keep diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c index e14ae3c4d4..b5cd74b25b 100644 --- a/lib/telemetry/telemetry_data.c +++ b/lib/telemetry/telemetry_data.c @@ -3,6 +3,8 @@ */ #undef RTE_USE_LIBBSD +#include + #include #include "telemetry_data.h" @@ -92,6 +94,24 @@ rte_tel_data_add_array_container(struct rte_tel_data *d, return 0; } +static bool +valid_name(const char *name) +{ + char allowed[128] = { + ['0' ... '9'] = 1, + ['A' ... 'Z'] = 1, + ['a' ... 'z'] = 1, + ['_'] = 1, + ['/'] = 1, + }; + while (*name != '\0') { + if ((size_t)*name >= RTE_DIM(allowed) || allowed[(int)*name] == 0) + return false; + name++; + } + return true; +} + int rte_tel_data_add_dict_string(struct rte_tel_data *d, const char *name, const char *val) @@ -104,6 +124,9 @@ rte_tel_data_add_dict_string(struct rte_tel_data *d, const char *name, if (d->data_len >= RTE_TEL_MAX_DICT_ENTRIES) return -ENOSPC; + if (!valid_name(name)) + return -EINVAL; + d->data_len++; e->type = RTE_TEL_STRING_VAL; vbytes = strlcpy(e->value.sval, val, RTE_TEL_MAX_STRING_LEN); @@ -123,6 +146,9 @@ rte_tel_data_add_dict_int(struct rte_tel_data *d, const char *name, int val) if (d->data_len >= RTE_TEL_MAX_DICT_ENTRIES) return -ENOSPC; + if (!valid_name(name)) + return -EINVAL; + d->data_len++; e->type = RTE_TEL_INT_VAL; e->value.ival = val; @@ -140,6 +166,9 @@ rte_tel_data_add_dict_u64(struct rte_tel_data *d, if (d->data_len >= RTE_TEL_MAX_DICT_ENTRIES) return -ENOSPC; + if (!valid_name(name)) + return -EINVAL; + d->data_len++; e->type = RTE_TEL_U64_VAL; e->value.u64val = val; @@ -161,6 +190,9 @@ rte_tel_data_add_dict_container(struct rte_tel_data *d, const char *name, if (d->data_len >= RTE_TEL_MAX_DICT_ENTRIES) return -ENOSPC; + if (!valid_name(name)) + return -EINVAL; + d->data_len++; e->type = RTE_TEL_CONTAINER; e->value.container.data = val; -- 2.34.1