[PATCH v5 20/22] cfgfile: fix section count with no name

Dumitrescu, Cristian cristian.dumitrescu at intel.com
Wed Jul 23 17:15:48 CEST 2025



> -----Original Message-----
> From: Richardson, Bruce <bruce.richardson at intel.com>
> Sent: Wednesday, July 23, 2025 4:08 PM
> To: Marchand, David <david.marchand at redhat.com>
> Cc: dev at dpdk.org; Dumitrescu, Cristian <cristian.dumitrescu at intel.com>; Allain
> Legacy <allain.legacy at windriver.com>
> Subject: Re: [PATCH v5 20/22] cfgfile: fix section count with no name
> 
> On Wed, Jul 23, 2025 at 03:31:53PM +0200, David Marchand wrote:
> > 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>
> Acked-by: Bruce Richardson <bruce.richardson at intel.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
> >

Acked-by: Cristian Dumitrescu <cristian.dumitrescu at intel.com>


More information about the dev mailing list