[dpdk-dev] app/testpmd: fix potential out of bounds read

Message ID 1425907269-20856-1-git-send-email-julien.cretin@trust-in-soft.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Julien Cretin March 9, 2015, 1:21 p.m. UTC
  After the last enabled port has been seen, and the last time we
evaluate the loop condition, there is an out of bounds read in
ports[p].enabled because p is equal to size, which is the length of
ports.

Signed-off-by: Julien Cretin <julien.cretin@trust-in-soft.com>
---
 app/test-pmd/testpmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Thomas Monjalon March 23, 2015, 11:36 a.m. UTC | #1
> After the last enabled port has been seen, and the last time we
> evaluate the loop condition, there is an out of bounds read in
> ports[p].enabled because p is equal to size, which is the length of
> ports.
> 
> Signed-off-by: Julien Cretin <julien.cretin@trust-in-soft.com>

Acked-by: Thomas Monjalon <thomas.monjalon@6wind.com>

Applied, thanks
  

Patch

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 3e1327e..a9d15f3 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -333,7 +333,7 @@  find_next_port(portid_t p, struct rte_port *ports, int size)
 	if (ports == NULL)
 		rte_exit(-EINVAL, "failed to find a next port id\n");
 
-	while ((ports[p].enabled == 0) && (p < size))
+	while ((p < size) && (ports[p].enabled == 0))
 		p++;
 	return p;
 }