app/testpmd: fix potential out of bounds read
[dpdk.git] / app / test-pmd / testpmd.c
index 3e1327e..3057791 100644 (file)
@@ -57,7 +57,6 @@
 #include <rte_memcpy.h>
 #include <rte_memzone.h>
 #include <rte_launch.h>
-#include <rte_tailq.h>
 #include <rte_eal.h>
 #include <rte_per_lcore.h>
 #include <rte_lcore.h>
@@ -333,7 +332,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;
 }
@@ -1634,6 +1633,9 @@ pmd_test_exit(void)
 {
        portid_t pt_id;
 
+       if (test_done == 0)
+               stop_packet_forwarding();
+
        FOREACH_PORT(pt_id, ports) {
                printf("Stopping port %d...", pt_id);
                fflush(stdout);