DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] app/testpmd: fix division by zero bug
@ 2021-04-21 11:38 Min Hu (Connor)
  2021-04-26 11:20 ` Ferruh Yigit
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Min Hu (Connor) @ 2021-04-21 11:38 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit, xiaoyun.li

Variable total, which may be zero and result in segmentation fault.

This patch fixed it.

Fixes: 9b1249d9ff69 ("app/testpmd: support dumping socket memory")
Cc: stable@dpdk.org

Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 app/test-pmd/cmdline.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 08da2b1..cde0a00 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -9631,6 +9631,9 @@ dump_socket_mem(FILE *f)
 			socket_stats.alloc_count,
 			socket_stats.free_count);
 	}
+
+	if (total == 0)
+		return;
 	fprintf(f,
 		"Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
 		(double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
-- 
2.7.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [PATCH] app/testpmd: fix division by zero bug
  2021-04-21 11:38 [dpdk-dev] [PATCH] app/testpmd: fix division by zero bug Min Hu (Connor)
@ 2021-04-26 11:20 ` Ferruh Yigit
  2021-04-26 11:57 ` [dpdk-dev] [PATCH v2] " Min Hu (Connor)
  2021-04-26 11:58 ` [dpdk-dev] [PATCH] " Min Hu (Connor)
  2 siblings, 0 replies; 5+ messages in thread
From: Ferruh Yigit @ 2021-04-26 11:20 UTC (permalink / raw)
  To: Min Hu (Connor), dev; +Cc: xiaoyun.li

On 4/21/2021 12:38 PM, Min Hu (Connor) wrote:
> Variable total, which may be zero and result in segmentation fault.
> 
> This patch fixed it.
> 
> Fixes: 9b1249d9ff69 ("app/testpmd: support dumping socket memory")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> ---
>   app/test-pmd/cmdline.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> index 08da2b1..cde0a00 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -9631,6 +9631,9 @@ dump_socket_mem(FILE *f)
>   			socket_stats.alloc_count,
>   			socket_stats.free_count);
>   	}
> +
> +	if (total == 0)
> +		return;
>   	fprintf(f,
>   		"Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
>   		(double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
> 

Hi Connor,

Not sure if the value can be zero on practice, but if the issue is found via 
static analyzer tool, instead of return from function without any output what 
about following instead:

  -               (double)alloc * 100 / (double)total,
  +               total ? ((double)alloc * 100 / (double)total) : 0,

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-dev] [PATCH v2] app/testpmd: fix division by zero bug
  2021-04-21 11:38 [dpdk-dev] [PATCH] app/testpmd: fix division by zero bug Min Hu (Connor)
  2021-04-26 11:20 ` Ferruh Yigit
@ 2021-04-26 11:57 ` Min Hu (Connor)
  2021-04-29 13:36   ` Ferruh Yigit
  2021-04-26 11:58 ` [dpdk-dev] [PATCH] " Min Hu (Connor)
  2 siblings, 1 reply; 5+ messages in thread
From: Min Hu (Connor) @ 2021-04-26 11:57 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit, xiaoyun.li

Variable total, which may be zero and result in segmentation fault.

This patch fixed it.

Fixes: 9b1249d9ff69 ("app/testpmd: support dumping socket memory")
Cc: stable@dpdk.org

Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 app/test-pmd/cmdline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 12efbc0..51d789e 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -9727,7 +9727,7 @@ dump_socket_mem(FILE *f)
 	fprintf(f,
 		"Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
 		(double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
-		(double)alloc * 100 / (double)total,
+		total ? ((double)alloc * 100 / (double)total) : 0,
 		(double)free / (1024 * 1024),
 		n_alloc, n_free);
 	if (last_allocs)
-- 
2.7.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [PATCH] app/testpmd: fix division by zero bug
  2021-04-21 11:38 [dpdk-dev] [PATCH] app/testpmd: fix division by zero bug Min Hu (Connor)
  2021-04-26 11:20 ` Ferruh Yigit
  2021-04-26 11:57 ` [dpdk-dev] [PATCH v2] " Min Hu (Connor)
@ 2021-04-26 11:58 ` Min Hu (Connor)
  2 siblings, 0 replies; 5+ messages in thread
From: Min Hu (Connor) @ 2021-04-26 11:58 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit, xiaoyun.li



在 2021/4/21 19:38, Min Hu (Connor) 写道:
> Variable total, which may be zero and result in segmentation fault.
> 
> This patch fixed it.
> 
> Fixes: 9b1249d9ff69 ("app/testpmd: support dumping socket memory")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> ---
>   app/test-pmd/cmdline.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> index 08da2b1..cde0a00 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -9631,6 +9631,9 @@ dump_socket_mem(FILE *f)
>   			socket_stats.alloc_count,
>   			socket_stats.free_count);
>   	}
> +
> +	if (total == 0)
> +		return;
>   	fprintf(f,
>   		"Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
>   		(double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
> 
Agreed, fixed in v2, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [PATCH v2] app/testpmd: fix division by zero bug
  2021-04-26 11:57 ` [dpdk-dev] [PATCH v2] " Min Hu (Connor)
@ 2021-04-29 13:36   ` Ferruh Yigit
  0 siblings, 0 replies; 5+ messages in thread
From: Ferruh Yigit @ 2021-04-29 13:36 UTC (permalink / raw)
  To: Min Hu (Connor), dev; +Cc: xiaoyun.li

On 4/26/2021 12:57 PM, Min Hu (Connor) wrote:
> Variable total, which may be zero and result in segmentation fault.
> 
> This patch fixed it.
> 
> Fixes: 9b1249d9ff69 ("app/testpmd: support dumping socket memory")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied to dpdk-next-net/main, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-29 13:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21 11:38 [dpdk-dev] [PATCH] app/testpmd: fix division by zero bug Min Hu (Connor)
2021-04-26 11:20 ` Ferruh Yigit
2021-04-26 11:57 ` [dpdk-dev] [PATCH v2] " Min Hu (Connor)
2021-04-29 13:36   ` Ferruh Yigit
2021-04-26 11:58 ` [dpdk-dev] [PATCH] " Min Hu (Connor)

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git