bus/fslmc: fix for resource leak coverity issue

Message ID 1568100655-20010-1-git-send-email-agalyax.babu.radhakrishnan@intel.com
State New
Delegated to: Thomas Monjalon
Headers show
Series
  • bus/fslmc: fix for resource leak coverity issue
Related show

Checks

Context Check Description
ci/mellanox-Performance success Performance Testing PASS
ci/intel-Performance success Performance Testing PASS
ci/iol-dpdk_compile_spdk success Compile Testing PASS
ci/iol-dpdk_compile success Compile Testing PASS
ci/iol-dpdk_compile_ovs success Compile Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Babu Radhakrishnan, AgalyaX Sept. 10, 2019, 7:30 a.m.
From: Agalya Babu RadhaKrishnan <agalyax.babu.radhakrishnan@intel.com>

1 issue caught by 344967
Leaked_storage: Variable sep going out of scope leaks the
storage it points to.

When 'sep' is not null and sep_exist is 0, 'sep' is freed
before going out of scope of the function irrespective of
'addr' exists or not.

Coverity Issue: 344967
Fixes: e67a61614d0b ("bus/fslmc: support device iteration")
Cc: stable@dpdk.org

Signed-off-by: Agalya Babu RadhaKrishnan <agalyax.babu.radhakrishnan@intel.com>
---
 drivers/bus/fslmc/fslmc_bus.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Babu Radhakrishnan, AgalyaX Sept. 10, 2019, 7:41 a.m. | #1
Hi,

> -----Original Message-----
> From: Babu Radhakrishnan, AgalyaX
> Sent: Tuesday, September 10, 2019 1:01 PM
> To: dev@dpdk.org
> Cc: Pattan, Reshma <reshma.pattan@intel.com>;
> hemant.agrawal@nxp.com; sachin.saxena@nxp.com; Parthasarathy,
> JananeeX M <jananeex.m.parthasarathy@intel.com>; Babu Radhakrishnan,
> AgalyaX <agalyax.babu.radhakrishnan@intel.com>; stable@dpdk.org
> Subject: [PATCH] bus/fslmc: fix for resource leak coverity issue
> 
> From: Agalya Babu RadhaKrishnan <agalyax.babu.radhakrishnan@intel.com>
> 
> 1 issue caught by 344967
> Leaked_storage: Variable sep going out of scope leaks the storage it points
> to.
> 
> When 'sep' is not null and sep_exist is 0, 'sep' is freed before going out of
> scope of the function irrespective of 'addr' exists or not.
> 
> Coverity Issue: 344967
> Fixes: e67a61614d0b ("bus/fslmc: support device iteration")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Agalya Babu RadhaKrishnan
> <agalyax.babu.radhakrishnan@intel.com>
> ---

if (strncmp("dpni", sep, 4) &&
            strncmp("dpseci", sep, 6) &&
            strncmp("dpcon", sep, 5) &
            .....

We think validation of device name is done using AND operator instead it should be done by OR operator.
Please confirm.
Sachin Saxena Oct. 3, 2019, 8:40 a.m. | #2
Acked-by: Sachin Saxena <sachin.saxena@nxp.com>

regards,
Sachin Saxena

> -----Original Message-----
> From: Agalya Babu RadhaKrishnan <agalyax.babu.radhakrishnan@intel.com>
> Sent: Tuesday, September 10, 2019 1:01 PM
> To: dev@dpdk.org
> Cc: reshma.pattan@intel.com; Hemant Agrawal
> <hemant.agrawal@nxp.com>; Sachin Saxena <sachin.saxena@nxp.com>;
> jananeex.m.parthasarathy@intel.com; Agalya Babu RadhaKrishnan
> <agalyax.babu.radhakrishnan@intel.com>; stable@dpdk.org
> Subject: [PATCH] bus/fslmc: fix for resource leak coverity issue
> Importance: High
> 
> From: Agalya Babu RadhaKrishnan <agalyax.babu.radhakrishnan@intel.com>
> 
> 1 issue caught by 344967
> Leaked_storage: Variable sep going out of scope leaks the storage it points
> to.
> 
> When 'sep' is not null and sep_exist is 0, 'sep' is freed before going out of
> scope of the function irrespective of 'addr' exists or not.
> 
> Coverity Issue: 344967
> Fixes: e67a61614d0b ("bus/fslmc: support device iteration")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Agalya Babu RadhaKrishnan
> <agalyax.babu.radhakrishnan@intel.com>
> ---
>  drivers/bus/fslmc/fslmc_bus.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
> index a2f482516..60c34098c 100644
> --- a/drivers/bus/fslmc/fslmc_bus.c
> +++ b/drivers/bus/fslmc/fslmc_bus.c
> @@ -291,10 +291,13 @@ rte_fslmc_parse(const char *name, void *addr)
>  		goto err_out;
>  	}
> 
> -	if (addr)
> +	if (addr) {
>  		strcpy(addr, sep);
> +		if (!sep_exists && sep)
> +			free(sep);
> +		return 0;
> +	}
> 
> -	return 0;
>  err_out:
>  	if (!sep_exists && sep)
>  		free(sep);
> --
> 2.14.1
Sachin Saxena Oct. 3, 2019, 8:43 a.m. | #3
> -----Original Message-----
> From: Babu Radhakrishnan, AgalyaX
> <agalyax.babu.radhakrishnan@intel.com>
> Sent: Tuesday, September 10, 2019 1:11 PM
> To: dev@dpdk.org
> Cc: Pattan, Reshma <reshma.pattan@intel.com>; Hemant Agrawal
> <hemant.agrawal@nxp.com>; Sachin Saxena <sachin.saxena@nxp.com>;
> Parthasarathy, JananeeX M <jananeex.m.parthasarathy@intel.com>;
> stable@dpdk.org
> Subject: RE: [PATCH] bus/fslmc: fix for resource leak coverity issue
> Importance: High
> 
> Hi,
> 
> > -----Original Message-----
> > From: Babu Radhakrishnan, AgalyaX
> > Sent: Tuesday, September 10, 2019 1:01 PM
> > To: dev@dpdk.org
> > Cc: Pattan, Reshma <reshma.pattan@intel.com>;
> hemant.agrawal@nxp.com;
> > sachin.saxena@nxp.com; Parthasarathy, JananeeX M
> > <jananeex.m.parthasarathy@intel.com>; Babu Radhakrishnan, AgalyaX
> > <agalyax.babu.radhakrishnan@intel.com>; stable@dpdk.org
> > Subject: [PATCH] bus/fslmc: fix for resource leak coverity issue
> >
> > From: Agalya Babu RadhaKrishnan
> <agalyax.babu.radhakrishnan@intel.com>
> >
> > 1 issue caught by 344967
> > Leaked_storage: Variable sep going out of scope leaks the storage it
> > points to.
> >
> > When 'sep' is not null and sep_exist is 0, 'sep' is freed before going
> > out of scope of the function irrespective of 'addr' exists or not.
> >
> > Coverity Issue: 344967
> > Fixes: e67a61614d0b ("bus/fslmc: support device iteration")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Agalya Babu RadhaKrishnan
> > <agalyax.babu.radhakrishnan@intel.com>
> > ---
> 
> if (strncmp("dpni", sep, 4) &&
>             strncmp("dpseci", sep, 6) &&
>             strncmp("dpcon", sep, 5) &
>             .....
> 
> We think validation of device name is done using AND operator instead it
> should be done by OR operator.
> Please confirm
[Sachin Saxena] The purpose of this logic to confirm that one of the device name should match to supported list and as soon as one strncmp() matches the string it will return 0 and the control comes out of IF condition.
So, existing logic is correct.

Patch

diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index a2f482516..60c34098c 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -291,10 +291,13 @@  rte_fslmc_parse(const char *name, void *addr)
 		goto err_out;
 	}
 
-	if (addr)
+	if (addr) {
 		strcpy(addr, sep);
+		if (!sep_exists && sep)
+			free(sep);
+		return 0;
+	}
 
-	return 0;
 err_out:
 	if (!sep_exists && sep)
 		free(sep);