DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>,
	Ciara Power <ciara.power@intel.com>
Subject: [PATCH v2 06/13] telemetry: limit characters allowed in dictionary names
Date: Mon, 25 Jul 2022 17:35:35 +0100	[thread overview]
Message-ID: <20220725163543.875775-7-bruce.richardson@intel.com> (raw)
In-Reply-To: <20220725163543.875775-1-bruce.richardson@intel.com>

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 <bruce.richardson@intel.com>
---
 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 <stdbool.h>
+
 #include <rte_string_fns.h>
 
 #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


  parent reply	other threads:[~2022-07-25 16:36 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23 16:42 [RFC PATCH 0/6] add json string escaping to telemetry Bruce Richardson
2022-06-23 16:42 ` [RFC PATCH 1/6] test/telemetry_json: print success or failure per subtest Bruce Richardson
2022-06-23 16:42 ` [RFC PATCH 2/6] telemetry: fix escaping of invalid json characters Bruce Richardson
2022-06-23 18:34   ` Morten Brørup
2022-06-23 18:39     ` Stephen Hemminger
2022-06-23 18:48       ` Morten Brørup
2022-06-24  8:00         ` Bruce Richardson
2022-06-24 11:16           ` Bruce Richardson
2022-06-24 11:29             ` Morten Brørup
2022-06-24 15:06               ` Stephen Hemminger
2022-06-24  8:03     ` Bruce Richardson
2022-06-23 16:42 ` [RFC PATCH 3/6] telemetry: use json string function for string outputs Bruce Richardson
2022-06-23 16:42 ` [RFC PATCH 4/6] test/telemetry_json: add test for string character escaping Bruce Richardson
2022-06-23 16:42 ` [RFC PATCH 5/6] telemetry: add escaping of strings in arrays Bruce Richardson
2022-06-23 16:42 ` [RFC PATCH 6/6] test/telemetry-json: add test case for escaping " Bruce Richardson
2022-06-23 19:04 ` [RFC PATCH 0/6] add json string escaping to telemetry Morten Brørup
2022-06-24  8:13   ` Bruce Richardson
2022-06-24  9:12     ` Morten Brørup
2022-06-24  9:17       ` Bruce Richardson
2022-06-24 10:22         ` Morten Brørup
2022-07-14 15:42 ` Morten Brørup
2022-07-25 16:38   ` Bruce Richardson
2022-07-25 16:35 ` [PATCH v2 00/13] telemetry JSON escaping and other enhancements Bruce Richardson
2022-07-25 16:35   ` [PATCH v2 01/13] test/telemetry_json: print success or failure per subtest Bruce Richardson
2022-07-25 16:35   ` [PATCH v2 02/13] telemetry: fix escaping of invalid json characters Bruce Richardson
2022-07-26 18:25     ` Morten Brørup
2022-07-27  8:21       ` Bruce Richardson
2022-07-27  1:13     ` fengchengwen
2022-07-27  8:27       ` Bruce Richardson
2022-07-25 16:35   ` [PATCH v2 03/13] test/telemetry_json: add test for string character escaping Bruce Richardson
2022-07-25 16:35   ` [PATCH v2 04/13] telemetry: add escaping of strings in arrays Bruce Richardson
2022-07-25 16:35   ` [PATCH v2 05/13] test/telemetry-json: add test for escaping " Bruce Richardson
2022-07-25 16:35   ` Bruce Richardson [this message]
2022-07-25 16:35   ` [PATCH v2 07/13] telemetry: add escaping of strings in dicts Bruce Richardson
2022-07-25 16:35   ` [PATCH v2 08/13] test/telemetry_json: add test for string escaping in objects Bruce Richardson
2022-07-25 16:35   ` [PATCH v2 09/13] telemetry: limit command characters Bruce Richardson
2022-07-25 16:35   ` [PATCH v2 10/13] test/telemetry_data: refactor for maintainability Bruce Richardson
2022-08-23 12:33     ` Power, Ciara
2022-07-25 16:35   ` [PATCH v2 11/13] test/telemetry_data: add test cases for character escaping Bruce Richardson
2022-07-25 16:35   ` [PATCH v2 12/13] telemetry: eliminate duplicate code for json output Bruce Richardson
2022-07-25 16:35   ` [PATCH v2 13/13] telemetry: make help command more helpful Bruce Richardson
2022-07-26 14:36   ` [PATCH v2 00/13] telemetry JSON escaping and other enhancements Morten Brørup
2022-07-27  1:51   ` fengchengwen
2022-07-27  9:12     ` Bruce Richardson
2022-07-27  9:49       ` Morten Brørup
2022-08-23 12:35   ` Power, Ciara
2022-09-09  9:35 ` [PATCH v3 " Bruce Richardson
2022-09-09  9:35   ` [PATCH v3 01/13] telemetry: limit characters allowed in dictionary names Bruce Richardson
2022-09-09  9:35   ` [PATCH v3 02/13] test/telemetry_json: print success or failure per subtest Bruce Richardson
2022-09-09  9:35   ` [PATCH v3 03/13] telemetry: fix escaping of invalid json characters Bruce Richardson
2022-09-09  9:35   ` [PATCH v3 04/13] test/telemetry_json: add test for string character escaping Bruce Richardson
2022-09-09  9:35   ` [PATCH v3 05/13] telemetry: add escaping of strings in arrays Bruce Richardson
2022-09-09  9:35   ` [PATCH v3 06/13] test/telemetry-json: add test for escaping " Bruce Richardson
2022-09-09  9:35   ` [PATCH v3 07/13] telemetry: add escaping of strings in dicts Bruce Richardson
2022-09-09  9:35   ` [PATCH v3 08/13] test/telemetry_json: add test for string escaping in objects Bruce Richardson
2022-09-09  9:35   ` [PATCH v3 09/13] telemetry: limit command characters Bruce Richardson
2022-09-09  9:35   ` [PATCH v3 10/13] test/telemetry_data: refactor for maintainability Bruce Richardson
2022-09-09  9:35   ` [PATCH v3 11/13] test/telemetry_data: add test cases for character escaping Bruce Richardson
2022-09-09  9:35   ` [PATCH v3 12/13] telemetry: eliminate duplicate code for json output Bruce Richardson
2022-09-09  9:35   ` [PATCH v3 13/13] telemetry: make help command more helpful Bruce Richardson
2022-09-13  0:35   ` [PATCH v3 00/13] telemetry JSON escaping and other enhancements fengchengwen
2022-09-26 11:52   ` David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220725163543.875775-7-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=ciara.power@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).