summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Simonart <xavier.simonart@intel.com>2018-10-28 15:54:28 +0100
committerDeepak S <deepak.s@linux.intel.com>2018-11-01 04:38:30 +0530
commit2d8609495ff4a58ceae13746f067fec6b0d5cf03 (patch)
tree92a35b7e6592fe907f861a9da7f18e8608ac7e3d
parentade1ef11e0c54bb782bea863721964c53024c8ea (diff)
Fix potential crash when shuffling mbufs
Change-Id: I70de6345afc6a696906f006c1b0f44540ae4ecec Signed-off-by: Xavier Simonart <xavier.simonart@intel.com>
-rw-r--r--VNFs/DPPD-PROX/main.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/VNFs/DPPD-PROX/main.c b/VNFs/DPPD-PROX/main.c
index 2e1616af..ec1ecb58 100644
--- a/VNFs/DPPD-PROX/main.c
+++ b/VNFs/DPPD-PROX/main.c
@@ -571,13 +571,14 @@ static void shuffle_mempool(struct rte_mempool* mempool, uint32_t nb_mbuf)
struct rte_mbuf** pkts = prox_zmalloc(nb_mbuf * sizeof(*pkts), rte_socket_id());
uint64_t got = 0;
- while (rte_mempool_get_bulk(mempool, (void**)(pkts + got), 1) == 0)
+ while ((got < nb_mbuf) && (rte_mempool_get_bulk(mempool, (void**)(pkts + got), 1) == 0))
++got;
+ nb_mbuf = got;
while (got) {
int idx;
do {
- idx = rand() % nb_mbuf - 1;
+ idx = rand() % nb_mbuf;
} while (pkts[idx] == 0);
rte_mempool_put_bulk(mempool, (void**)&pkts[idx], 1);