From cda3f638c348b4ad35eb2492bf2ff8e1296f1489 Mon Sep 17 00:00:00 2001 From: Sergio Gonzalez Monroy Date: Thu, 18 Jun 2015 13:27:30 +0100 Subject: [PATCH] ivshmem: fix crash in corner case Depending on the configured segments it is possible to hit a segmentation fault as a result of decrementing an unsigned index with value 0. To avoid it, exit the loop if the index has value 0. Fixes: 40b966a211ab ("ivshmem: library changes for mmaping using ivshmem") Signed-off-by: Sergio Gonzalez Monroy --- lib/librte_ivshmem/rte_ivshmem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/librte_ivshmem/rte_ivshmem.c b/lib/librte_ivshmem/rte_ivshmem.c index 7ca55edb91..9621906d07 100644 --- a/lib/librte_ivshmem/rte_ivshmem.c +++ b/lib/librte_ivshmem/rte_ivshmem.c @@ -377,6 +377,8 @@ build_config(struct rte_ivshmem_metadata * metadata) for (j = biggest_idx - 1; j >= i; j--) { memcpy(&pages[j+1], &pages[j], sizeof(struct rte_memseg)); memset(&pages[j], 0, sizeof(struct rte_memseg)); + if (j == 0) + break; } /* put old biggest segment to its new place */ -- 2.20.1