[v3] app/test-fib: fix possible division by zero

Message ID 20220127180853.1131512-1-vladimir.medvedkin@intel.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [v3] app/test-fib: fix possible division by zero |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing fail Testing issues
ci/Intel-compilation success Compilation OK
ci/intel-Testing fail Testing issues
ci/iol-abi-testing warning Testing issues

Commit Message

Vladimir Medvedkin Jan. 27, 2022, 6:08 p.m. UTC
  This patch fixes the division by 0,
which occurs if the number of routes is less than 10.
Can be triggered by passing -n argument with value < 10:

./dpdk-test-fib -- -n 9
...
Floating point exception (core dumped)

Fixes: 103809d032cd ("app/test-fib: add test application for FIB")
Cc: stable@dpdk.org

Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
---
 app/test-fib/main.c | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Kevin Traynor Jan. 28, 2022, 5:44 p.m. UTC | #1
On 27/01/2022 18:08, Vladimir Medvedkin wrote:
> This patch fixes the division by 0,
> which occurs if the number of routes is less than 10.
> Can be triggered by passing -n argument with value < 10:
> 
> ./dpdk-test-fib -- -n 9
> ...
> Floating point exception (core dumped)
> 
> Fixes: 103809d032cd ("app/test-fib: add test application for FIB")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
> ---

This looks a better solution, and thanks for adding the tags.

Acked-by: Kevin Traynor <ktraynor@redhat.com>

>   app/test-fib/main.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/app/test-fib/main.c b/app/test-fib/main.c
> index ecd420116a..067c5284f9 100644
> --- a/app/test-fib/main.c
> +++ b/app/test-fib/main.c
> @@ -711,6 +711,10 @@ parse_opts(int argc, char **argv)
>   				print_usage();
>   				rte_exit(-EINVAL, "Invalid option -n\n");
>   			}
> +
> +			if (config.nb_routes < config.print_fract)
> +				config.print_fract = config.nb_routes;
> +
>   			break;
>   		case 'd':
>   			distrib_string = optarg;
> @@ -1242,6 +1246,10 @@ main(int argc, char **argv)
>   		config.nb_routes = 0;
>   		while (fgets(line, sizeof(line), fr) != NULL)
>   			config.nb_routes++;
> +
> +		if (config.nb_routes < config.print_fract)
> +			config.print_fract = config.nb_routes;
> +
>   		rewind(fr);
>   	}
>   
>
  
David Marchand Feb. 11, 2022, 7:55 a.m. UTC | #2
On Fri, Jan 28, 2022 at 6:44 PM Kevin Traynor <ktraynor@redhat.com> wrote:
>
> On 27/01/2022 18:08, Vladimir Medvedkin wrote:
> > This patch fixes the division by 0,
> > which occurs if the number of routes is less than 10.
> > Can be triggered by passing -n argument with value < 10:
> >
> > ./dpdk-test-fib -- -n 9
> > ...
> > Floating point exception (core dumped)
> >
> > Fixes: 103809d032cd ("app/test-fib: add test application for FIB")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
> Acked-by: Kevin Traynor <ktraynor@redhat.com>

Applied, thanks.
  

Patch

diff --git a/app/test-fib/main.c b/app/test-fib/main.c
index ecd420116a..067c5284f9 100644
--- a/app/test-fib/main.c
+++ b/app/test-fib/main.c
@@ -711,6 +711,10 @@  parse_opts(int argc, char **argv)
 				print_usage();
 				rte_exit(-EINVAL, "Invalid option -n\n");
 			}
+
+			if (config.nb_routes < config.print_fract)
+				config.print_fract = config.nb_routes;
+
 			break;
 		case 'd':
 			distrib_string = optarg;
@@ -1242,6 +1246,10 @@  main(int argc, char **argv)
 		config.nb_routes = 0;
 		while (fgets(line, sizeof(line), fr) != NULL)
 			config.nb_routes++;
+
+		if (config.nb_routes < config.print_fract)
+			config.print_fract = config.nb_routes;
+
 		rewind(fr);
 	}