[2/4] cfgfile: support verify name and value
Checks
Commit Message
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(+)
Comments
On Tue, 20 Feb 2024 03:58:38 +0000
Chengwen Feng <fengchengwen@huawei.com> wrote:
> 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>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
@@ -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) {