From patchwork Wed Apr 27 17:06:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mrzyglod X-Patchwork-Id: 12280 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 4B70D37B0; Wed, 27 Apr 2016 18:03:53 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id E62E637AF for ; Wed, 27 Apr 2016 18:03:51 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 27 Apr 2016 09:03:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,542,1455004800"; d="scan'208";a="963935356" Received: from gklab-246-025.igk.intel.com (HELO Sent) ([10.217.246.25]) by orsmga002.jf.intel.com with SMTP; 27 Apr 2016 09:03:27 -0700 Received: by Sent (sSMTP sendmail emulation); Wed, 27 Apr 2016 19:06:05 +0200 From: Daniel Mrzyglod To: david.marchand@6wind.com, sergio.gonzalez.monroy@intel.com Cc: dev@dpdk.org, Daniel Mrzyglod Date: Wed, 27 Apr 2016 19:06:04 +0200 Message-Id: <1461776764-108197-1-git-send-email-danielx.t.mrzyglod@intel.com> X-Mailer: git-send-email 2.5.5 Subject: [dpdk-dev] [PATCH] eal/linux: fix undefined allocation of 0 bytes (CERT MEM04-C; CWE-131) 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Fix issue reported by clang scan-build there is a chance that nr_hugepages will be 0 if conditions for loop for (i = 0; i < (int) internal_config.num_hugepage_sizes; i++) will be unmeet. Fixes: b6a468ad41d5 ("memory: add --socket-mem option") Signed-off-by: Daniel Mrzyglod --- lib/librte_eal/linuxapp/eal/eal_memory.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index 5b9132c..e94538e 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -1114,6 +1114,8 @@ rte_eal_hugepage_init(void) * processing done on these pages, shared memory will be created * at a later stage. */ + if (nr_hugepages == 0) + goto fail; tmp_hp = malloc(nr_hugepages * sizeof(struct hugepage_file)); if (tmp_hp == NULL) goto fail;