From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
To: dev@dpdk.org
Cc: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
Harini Ramakrishnan <harini.ramakrishnan@microsoft.com>,
Omar Cardona <ocardona@microsoft.com>,
Pallavi Kadam <pallavi.kadam@intel.com>,
Ranjit Menon <ranjit.menon@intel.com>
Subject: [dpdk-dev] [PATCH] eal/windows: fix out-of-memory check
Date: Mon, 17 Feb 2020 05:23:51 +0300 [thread overview]
Message-ID: <20200217022351.59429-1-dmitry.kozliuk@gmail.com> (raw)
Check vsnprintf() result to prevent calling malloc() with negative size.
Check actual malloc() result and terminate asprintf() with documented
error code to prevent the use of NULL pointer.
Fixes: e8428a9d8 ("eal/windows: add some basic functions and macros")
Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
lib/librte_eal/windows/eal/include/rte_os.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/librte_eal/windows/eal/include/rte_os.h b/lib/librte_eal/windows/eal/include/rte_os.h
index 9e762617b..69e8f4733 100644
--- a/lib/librte_eal/windows/eal/include/rte_os.h
+++ b/lib/librte_eal/windows/eal/include/rte_os.h
@@ -66,10 +66,12 @@ asprintf(char **buffer, const char *format, ...)
va_start(arg, format);
size = vsnprintf(NULL, 0, format, arg) + 1;
va_end(arg);
+ if (size < 0)
+ return -1;
*buffer = malloc(size);
- if (buffer == NULL)
- printf("Cannot allocate memory");
+ if (*buffer == NULL)
+ return -1;
va_start(arg, format);
ret = vsnprintf(*buffer, size, format, arg);
--
2.25.0
next reply other threads:[~2020-02-17 2:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-17 2:23 Dmitry Kozlyuk [this message]
2020-02-17 23:56 ` [dpdk-dev] [PATCH v2] " Dmitry Kozlyuk
2020-02-18 21:52 ` Ranjit Menon
2020-02-21 16:37 ` Thomas Monjalon
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=20200217022351.59429-1-dmitry.kozliuk@gmail.com \
--to=dmitry.kozliuk@gmail.com \
--cc=dev@dpdk.org \
--cc=harini.ramakrishnan@microsoft.com \
--cc=ocardona@microsoft.com \
--cc=pallavi.kadam@intel.com \
--cc=ranjit.menon@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).