From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id E0E66C5FA for ; Thu, 18 Jun 2015 14:27:32 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 18 Jun 2015 05:27:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,638,1427785200"; d="scan'208";a="590215005" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 18 Jun 2015 05:27:32 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t5ICRUA1022970 for ; Thu, 18 Jun 2015 13:27:30 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id t5ICRUpc010535 for ; Thu, 18 Jun 2015 13:27:30 +0100 Received: (from smonroy@localhost) by sivswdev02.ir.intel.com with id t5ICRUj8010531 for dev@dpdk.org; Thu, 18 Jun 2015 13:27:30 +0100 From: Sergio Gonzalez Monroy To: dev@dpdk.org Date: Thu, 18 Jun 2015 13:27:30 +0100 Message-Id: <1434630450-10497-1-git-send-email-sergio.gonzalez.monroy@intel.com> X-Mailer: git-send-email 1.8.5.4 Subject: [dpdk-dev] [PATCH] ivshmem: fix segmentation fault in corner case X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jun 2015 12:27:33 -0000 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. 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 7ca55ed..9621906 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 */ -- 1.9.3