[PATCH v5 20/22] cfgfile: fix section count with no name
David Marchand
david.marchand at redhat.com
Wed Jul 23 15:31:53 CEST 2025
Passing a NULL to strncmp is incorrect.
+ ------------------------------------------------------- +
+ Test Suite : Test Cfgfile Unit Test Suite
+ ------------------------------------------------------- +
../lib/cfgfile/rte_cfgfile.c:475:7: runtime error: null pointer passed as
argument 2, which is declared to never be null
On the other hand, it seems the intent was to count all sections, so
skip the whole loop and section name comparisons.
Fixes: c54e7234bc9e ("test/cfgfile: add basic unit tests")
Signed-off-by: David Marchand <david.marchand at redhat.com>
---
lib/cfgfile/rte_cfgfile.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/cfgfile/rte_cfgfile.c b/lib/cfgfile/rte_cfgfile.c
index 8bbdcf146e..9723ec756f 100644
--- a/lib/cfgfile/rte_cfgfile.c
+++ b/lib/cfgfile/rte_cfgfile.c
@@ -477,10 +477,14 @@ int rte_cfgfile_close(struct rte_cfgfile *cfg)
RTE_EXPORT_SYMBOL(rte_cfgfile_num_sections)
int
rte_cfgfile_num_sections(struct rte_cfgfile *cfg, const char *sectionname,
-size_t length)
+ size_t length)
{
- int i;
int num_sections = 0;
+ int i;
+
+ if (sectionname == NULL)
+ return cfg->num_sections;
+
for (i = 0; i < cfg->num_sections; i++) {
if (strncmp(cfg->sections[i].name, sectionname, length) == 0)
num_sections++;
--
2.50.0
More information about the dev
mailing list