DPDK patches and discussions
 help / color / mirror / Atom feed
From: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
To: david.marchand@6wind.com, sergio.gonzalez.monroy@intel.com
Cc: dev@dpdk.org, Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
Subject: [dpdk-dev] [PATCH] eal/linux: fix undefined allocation of 0 bytes (CERT MEM04-C; CWE-131)
Date: Wed, 27 Apr 2016 19:06:04 +0200	[thread overview]
Message-ID: <1461776764-108197-1-git-send-email-danielx.t.mrzyglod@intel.com> (raw)

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 <danielx.t.mrzyglod@intel.com>
---
 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;
-- 
2.5.5

             reply	other threads:[~2016-04-27 16:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-27 17:06 Daniel Mrzyglod [this message]
2016-06-08 12:42 ` Sergio Gonzalez Monroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1461776764-108197-1-git-send-email-danielx.t.mrzyglod@intel.com \
    --to=danielx.t.mrzyglod@intel.com \
    --cc=david.marchand@6wind.com \
    --cc=dev@dpdk.org \
    --cc=sergio.gonzalez.monroy@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).