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

Cc: sta...@dpdk.org

Signed-off-by: Chengwen Feng <fengcheng...@huawei.com>
Acked-by: Stephen Hemminger <step...@networkplumber.org>
---
 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 6a98e8fb11..97a399635e 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

Reply via email to