From: Ferruh Yigit Date: Wed, 19 Feb 2020 12:40:03 +0000 (+0000) Subject: app/testpmd: guarantee port array access in range X-Git-Url: http://git.droids-corp.org/?p=dpdk.git;a=commitdiff_plain;h=5e4154cec49cb30c82c19c13fb62827e13563019 app/testpmd: guarantee port array access in range Coverity complains about out of bound access, which is a false positive. The return value of the 'parse_port_list()' can't be bigger than 'maxsize' because of the logic in the function. ('value >= (int)maxsize' check and 'marked[]' usage.) But this is not explicitly clear, causing coverity warning and same question can be rise by reviews later. Adding a redundant check to highlight the access is in range, this is done by replacing existing redundant check. This is also good to protect against out out bound access in case 'parse_port_list()' behaviour changes later unexpectedly. Coverity issue: 354229 Fixes: 2df00d562d20 ("app/testpmd: add --portlist option") Signed-off-by: Ferruh Yigit Reviewed-by: Herakliusz Lipiec Acked-by: Bernard Iremonger --- diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 9d95202233..d93941f031 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -2703,7 +2703,7 @@ parse_fwd_portlist(const char *portlist) * and thereby calculate the total number of * valid ports */ - for (i = 0; i < portcount && valid_port_count < portcount; i++) { + for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) { if (rte_eth_dev_is_valid_port(portindex[i])) { portindex[valid_port_count] = portindex[i]; valid_port_count++;