[2/2] graph: fix dereferencing null pointer

Message ID 1619092340-4047-3-git-send-email-humin29@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series bugfix for graph |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot success github build: passed
ci/Intel-compilation fail apply issues

Commit Message

humin (Q) April 22, 2021, 11:52 a.m. UTC
  From: HongBo Zheng <zhenghongbo3@huawei.com>

In function 'stats_mem_init', pointer 'stats' should
be confirmed not null before memset it.

Fixes: af1ae8b6a32c ("graph: implement stats")
Cc: stable@dpdk.org

Signed-off-by: HongBo Zheng <zhenghongbo3@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 lib/librte_graph/graph_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Kiran Kumar Kokkilagadda April 23, 2021, 3:52 a.m. UTC | #1
> -----Original Message-----
> From: Min Hu (Connor) <humin29@huawei.com>
> Sent: Thursday, April 22, 2021 5:22 PM
> To: dev@dpdk.org
> Cc: ferruh.yigit@intel.com; Jerin Jacob Kollanukkaran <jerinj@marvell.com>;
> Kiran Kumar Kokkilagadda <kirankumark@marvell.com>
> Subject: [EXT] [PATCH 2/2] graph: fix dereferencing null pointer
> 
> External Email
> 
> ----------------------------------------------------------------------
> From: HongBo Zheng <zhenghongbo3@huawei.com>
> 
> In function 'stats_mem_init', pointer 'stats' should be confirmed not null before
> memset it.
> 
> Fixes: af1ae8b6a32c ("graph: implement stats")
> Cc: stable@dpdk.org
> 
> Signed-off-by: HongBo Zheng <zhenghongbo3@huawei.com>
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> ---
>  lib/librte_graph/graph_stats.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_graph/graph_stats.c b/lib/librte_graph/graph_stats.c index
> f698bb3..bdc8652 100644
> --- a/lib/librte_graph/graph_stats.c
> +++ b/lib/librte_graph/graph_stats.c
> @@ -119,8 +119,8 @@ stats_mem_init(struct cluster *cluster,
>  	cluster_node_size = RTE_ALIGN(cluster_node_size,
> RTE_CACHE_LINE_SIZE);
> 
>  	stats = realloc(NULL, sz);
> -	memset(stats, 0, sz);
>  	if (stats) {
> +		memset(stats, 0, sz);
>  		stats->fn = fn;
>  		stats->cluster_node_size = cluster_node_size;
>  		stats->max_nodes = 0;
> --
> 2.7.4

Reviewed-by: Kiran Kumar K <kirankumark@marvell.com>
  
Jerin Jacob April 23, 2021, 9:05 a.m. UTC | #2
On Thu, Apr 22, 2021 at 5:22 PM Min Hu (Connor) <humin29@huawei.com> wrote:
>
> From: HongBo Zheng <zhenghongbo3@huawei.com>
>
> In function 'stats_mem_init', pointer 'stats' should
> be confirmed not null before memset it.
>
> Fixes: af1ae8b6a32c ("graph: implement stats")
> Cc: stable@dpdk.org
>
> Signed-off-by: HongBo Zheng <zhenghongbo3@huawei.com>
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> ---
>  lib/librte_graph/graph_stats.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/librte_graph/graph_stats.c b/lib/librte_graph/graph_stats.c

The directory name is changed in upstream. Please rebase.

Acked-by: Jerin Jacob <jerinj@marvell.com>




> index f698bb3..bdc8652 100644
> --- a/lib/librte_graph/graph_stats.c
> +++ b/lib/librte_graph/graph_stats.c
> @@ -119,8 +119,8 @@ stats_mem_init(struct cluster *cluster,
>         cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE);
>
>         stats = realloc(NULL, sz);
> -       memset(stats, 0, sz);
>         if (stats) {
> +               memset(stats, 0, sz);
>                 stats->fn = fn;
>                 stats->cluster_node_size = cluster_node_size;
>                 stats->max_nodes = 0;
> --
> 2.7.4
>
  

Patch

diff --git a/lib/librte_graph/graph_stats.c b/lib/librte_graph/graph_stats.c
index f698bb3..bdc8652 100644
--- a/lib/librte_graph/graph_stats.c
+++ b/lib/librte_graph/graph_stats.c
@@ -119,8 +119,8 @@  stats_mem_init(struct cluster *cluster,
 	cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE);
 
 	stats = realloc(NULL, sz);
-	memset(stats, 0, sz);
 	if (stats) {
+		memset(stats, 0, sz);
 		stats->fn = fn;
 		stats->cluster_node_size = cluster_node_size;
 		stats->max_nodes = 0;