From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 426F6CFD8 for ; Tue, 17 Apr 2018 17:42:33 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Apr 2018 08:42:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,464,1517904000"; d="scan'208";a="43994186" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 17 Apr 2018 08:42:30 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w3HFgUMk029677; Tue, 17 Apr 2018 16:42:30 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w3HFgUuN020528; Tue, 17 Apr 2018 16:42:30 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w3HFgU0I020524; Tue, 17 Apr 2018 16:42:30 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: thomas@monjalon.net, anatoly.burakov@intel.com Date: Tue, 17 Apr 2018 16:42:28 +0100 Message-Id: <8fc9683d48cddb0615f1f1d4482790f54bd8e317.1523977960.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 1/2] eal: fix potential negative return X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Apr 2018 15:42:33 -0000 Value returned by rte_socket_id_by_idx() may be negative, which would result in negative array index access. Coverity issue: 272600 Fixes: b666f17858a3 ("mem: read hugepage counts from node-specific sysfs path") Cc: anatoly.burakov@intel.com Signed-off-by: Anatoly Burakov --- lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c index fb4b667..009f963 100644 --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c @@ -402,9 +402,16 @@ hugepage_info_init(void) /* we also don't want to do this for legacy init */ if (!internal_config.legacy_mem) for (i = 0; i < rte_socket_count(); i++) { - int socket = rte_socket_id_by_idx(i); - unsigned int num_pages = - get_num_hugepages_on_node( + int socket; + unsigned int num_pages; + + socket = rte_socket_id_by_idx(i); + if (socket < 0) { + RTE_LOG(ERR, EAL, "Invalid socket index: %u\n", + i); + continue; + } + num_pages = get_num_hugepages_on_node( dirent->d_name, socket); hpi->num_pages[socket] = num_pages; total_pages += num_pages; -- 2.7.4