Check lcore id value is not the maximum core supported.
Using lcore id without this check might cause
out of bound access inside the rte_eal_wait_lcore.

Coverity issue: 375841
Fixes: b2854d5317e8 ("app/pdump: support multi-core capture")
Cc: vipin.vargh...@intel.com
Cc: sta...@dpdk.org

Signed-off-by: Reshma Pattan <reshma.pat...@intel.com>
---
v3: add new function to get next core id and validate it.
---
 app/pdump/main.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 04a38e8911..e4e62811c9 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -900,6 +900,15 @@ dump_packets_core(void *arg)
        return 0;
 }
 
+static inline void
+get_next_core(uint32_t *lcore_id)
+{
+       *lcore_id = rte_get_next_lcore(*lcore_id, 1, 0);
+       if (*lcore_id == RTE_MAX_LCORE)
+               rte_exit(EXIT_FAILURE,
+                               "Max core limit %u reached for packet capture", 
*lcore_id);
+}
+
 static inline void
 dump_packets(void)
 {
@@ -930,12 +939,12 @@ dump_packets(void)
                return;
        }
 
-       lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
+       get_next_core(&lcore_id);
 
        for (i = 0; i < num_tuples; i++) {
                rte_eal_remote_launch(dump_packets_core,
                                &pdump_t[i], lcore_id);
-               lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
+               get_next_core(&lcore_id);
 
                if (rte_eal_wait_lcore(lcore_id) < 0)
                        rte_exit(EXIT_FAILURE, "failed to wait\n");
-- 
2.25.1

Reply via email to