[v2,1/1] app/testpmd: fix invalid memory access

Message ID 20211012083317.399870-1-skori@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v2,1/1] app/testpmd: fix invalid memory access |

Checks

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

Commit Message

Sunil Kumar Kori Oct. 12, 2021, 8:33 a.m. UTC
  From: Sunil Kumar Kori <skori@marvell.com>

During parsing of DSCP entries, memory is allocated and assigned
to *dscp_table. Later on, same memory is accessed using
*dscp_table[i++].

Due to higher precedence for array subscript, dscp_table[i++] will
be executed first which actually does not point to the same memory
which was allocated previously for DSCP table entries.

Cc: stable@dpdk.org

Fixes: 459463ae6c26 ("app/testpmd: fix memory allocation for DSCP table")

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
---
v2:
 - Correct spelling mistakes
 - Correct fixes tag

 app/test-pmd/cmdline_mtr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Ferruh Yigit Oct. 19, 2021, 4:11 p.m. UTC | #1
On 10/12/2021 9:33 AM, skori@marvell.com wrote:
> From: Sunil Kumar Kori <skori@marvell.com>
> 
> During parsing of DSCP entries, memory is allocated and assigned
> to *dscp_table. Later on, same memory is accessed using
> *dscp_table[i++].
> 
> Due to higher precedence for array subscript, dscp_table[i++] will
> be executed first which actually does not point to the same memory
> which was allocated previously for DSCP table entries.
> 

Of course, thanks for the fix.

> Cc: stable@dpdk.org
> 
> Fixes: 459463ae6c26 ("app/testpmd: fix memory allocation for DSCP table")
> 
> Signed-off-by: Sunil Kumar Kori <skori@marvell.com>

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

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

Patch

diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c
index b5dcfdadcf..ad7ef6ad98 100644
--- a/app/test-pmd/cmdline_mtr.c
+++ b/app/test-pmd/cmdline_mtr.c
@@ -101,13 +101,13 @@  parse_dscp_table_entries(char *str, enum rte_color **dscp_table)
 	while (1) {
 		if (strcmp(token, "G") == 0 ||
 			strcmp(token, "g") == 0)
-			*dscp_table[i++] = RTE_COLOR_GREEN;
+			(*dscp_table)[i++] = RTE_COLOR_GREEN;
 		else if (strcmp(token, "Y") == 0 ||
 			strcmp(token, "y") == 0)
-			*dscp_table[i++] = RTE_COLOR_YELLOW;
+			(*dscp_table)[i++] = RTE_COLOR_YELLOW;
 		else if (strcmp(token, "R") == 0 ||
 			strcmp(token, "r") == 0)
-			*dscp_table[i++] = RTE_COLOR_RED;
+			(*dscp_table)[i++] = RTE_COLOR_RED;
 		else {
 			free(*dscp_table);
 			return -1;