Skip to contentSkip to conversation

app/testpmd: guarantee that array access is in range

PATCH In review Ferruh Yigit 3 participants 4 messages Feb 19, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 app/testpmd: guarantee that array access is 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")
---
 app/test-pmd/config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test-pmd/config.c +1 -1
index 9d9520223..d93941f03 100644
@@ -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++;
Signature · 1 line
2.24.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 49 lines

-----Original Message-----
From: Yigit, Ferruh <[email protected]>
Sent: Wednesday, February 19, 2020 12:40 PM
To: Lu, Wenzhuo <[email protected]>; Wu, Jingjing <[email protected]>; Iremonger, Bernard <[email protected]>; Lipiec, Herakliusz <[email protected]>; Govindharajan, Hariprasad <[email protected]>; Burakov, Anatoly <[email protected]>
Cc: [email protected]; Yigit, Ferruh <[email protected]>
Subject: [PATCH] app/testpmd: guarantee that array access is 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")
---
 app/test-pmd/config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test-pmd/config.c index renamed from app/test-pmd/config.c +0 -0

9d9520223..d93941f03 100644

app/test-pmd/config.c +1 -2
@@ -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++;
--
Quoted 1 line

2.24.1

Acked-by on v1 1/1
#2 lore raw
In reply to Ferruh Yigit
Quoted 26 lines

-----Original Message-----
From: Yigit, Ferruh <[email protected]>
Sent: Wednesday, February 19, 2020 12:40 PM
To: Lu, Wenzhuo <[email protected]>; Wu, Jingjing <[email protected]>; Iremonger, Bernard <[email protected]>; Lipiec, Herakliusz <[email protected]>; Govindharajan, Hariprasad <[email protected]>; Burakov, Anatoly <[email protected]>
Cc: [email protected]; Yigit, Ferruh <[email protected]>
Subject: [PATCH] app/testpmd: guarantee that array access is 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.

Quoted 7 lines

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")
author Applied
#3 lore raw
Quoted 29 lines · Bernard
Quoted 29 lines

-----Original Message-----
From: Yigit, Ferruh <[email protected]>
Sent: Wednesday, February 19, 2020 12:40 PM
To: Lu, Wenzhuo <[email protected]>; Wu, Jingjing <[email protected]>; Iremonger, Bernard <[email protected]>; Lipiec, Herakliusz <[email protected]>; Govindharajan, Hariprasad <[email protected]>; Burakov, Anatoly <[email protected]>
Cc: [email protected]; Yigit, Ferruh <[email protected]>
Subject: [PATCH] app/testpmd: guarantee that array access is 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.

Quoted 7 lines
Quoted 4 lines

Coverity issue: 354229

Fixes 2df00d562d20 ("app/testpmd: add --portlist option")

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