DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chengwen Feng <fengchengwen@huawei.com>
To: <thomas@monjalon.net>
Cc: <dev@dpdk.org>, <cristian.dumitrescu@intel.com>
Subject: [PATCH 2/4] cfgfile: support verify name and value
Date: Tue, 20 Feb 2024 03:58:38 +0000	[thread overview]
Message-ID: <20240220035840.32978-3-fengchengwen@huawei.com> (raw)
In-Reply-To: <20240220035840.32978-1-fengchengwen@huawei.com>

This patch supports verify section's name, entry's name and entry's
value validity.

Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/cfgfile/rte_cfgfile.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lib/cfgfile/rte_cfgfile.c b/lib/cfgfile/rte_cfgfile.c
index d7aa38b56f..6f8f46a406 100644
--- a/lib/cfgfile/rte_cfgfile.c
+++ b/lib/cfgfile/rte_cfgfile.c
@@ -105,6 +105,16 @@ static int
 _add_entry(struct rte_cfgfile_section *section, const char *entryname,
 		const char *entryvalue)
 {
+	int name_len, value_len;
+
+	name_len = strlen(entryname);
+	value_len = strlen(entryvalue);
+	if (name_len == 0 || name_len >= CFG_NAME_LEN || value_len >= CFG_VALUE_LEN) {
+		CFG_LOG(ERR, "invalid entry name %s or value %s in section %s",
+			entryname, entryvalue, section->name);
+		return -EINVAL;
+	}
+
 	/* resize entry structure if we don't have room for more entries */
 	if (section->num_entries == section->allocated_entries) {
 		struct rte_cfgfile_entry *n_entries = realloc(
@@ -322,6 +332,7 @@ rte_cfgfile_create(int flags)
 int
 rte_cfgfile_add_section(struct rte_cfgfile *cfg, const char *sectionname)
 {
+	int len;
 	int i;
 
 	if (cfg == NULL)
@@ -330,6 +341,12 @@ rte_cfgfile_add_section(struct rte_cfgfile *cfg, const char *sectionname)
 	if (sectionname == NULL)
 		return -EINVAL;
 
+	len = strlen(sectionname);
+	if (len == 0 || len >= CFG_NAME_LEN) {
+		CFG_LOG(ERR, "invalid section name %s", sectionname);
+		return -EINVAL;
+	}
+
 	/* resize overall struct if we don't have room for more	sections */
 	if (cfg->num_sections == cfg->allocated_sections) {
 
-- 
2.17.1


  parent reply	other threads:[~2024-02-20  4:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20  3:58 [PATCH 0/4] cfgfile: enhance error detecting Chengwen Feng
2024-02-20  3:58 ` [PATCH 1/4] cfgfile: remove dead code Chengwen Feng
2024-07-04 21:28   ` Stephen Hemminger
2024-02-20  3:58 ` Chengwen Feng [this message]
2024-07-04 21:29   ` [PATCH 2/4] cfgfile: support verify name and value Stephen Hemminger
2024-02-20  3:58 ` [PATCH 3/4] cfgfile: verify add section and entry result Chengwen Feng
2024-07-04 21:30   ` Stephen Hemminger
2024-02-20  3:58 ` [PATCH 4/4] cfgfile: add unique name flag Chengwen Feng
2024-07-04 21:36   ` Stephen Hemminger
2024-07-05  9:37     ` fengchengwen
2024-07-04 15:12 ` [PATCH 0/4] cfgfile: enhance error detecting David Marchand
2024-07-05  0:14   ` Stephen Hemminger
2024-07-05  0:29     ` Stephen Hemminger
2024-07-04 21:40 ` Stephen Hemminger
2024-07-05  8:39   ` Bruce Richardson
2024-07-05  9:31 ` [PATCH v2 " Chengwen Feng
2024-07-05  9:31   ` [PATCH v2 1/4] cfgfile: remove dead code Chengwen Feng
2024-07-05  9:31   ` [PATCH v2 2/4] cfgfile: support verify name and value Chengwen Feng
2024-07-05  9:31   ` [PATCH v2 3/4] cfgfile: verify add section and entry result Chengwen Feng
2024-07-05  9:31   ` [PATCH v2 4/4] cfgfile: add strict parse flag Chengwen Feng
2024-09-06  1:03   ` [PATCH v2 0/4] cfgfile: enhance error detecting fengchengwen
2024-10-09 22:47   ` Stephen Hemminger

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=20240220035840.32978-3-fengchengwen@huawei.com \
    --to=fengchengwen@huawei.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    /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).