From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] eal: check vsnprintf failure and return -EINVAL
Date: Mon, 15 Mar 2021 16:55:24 -0700 [thread overview]
Message-ID: <1615852524-3605-1-git-send-email-roretzla@linux.microsoft.com> (raw)
Check for failure, while here just increment len once after checking for
failure instead of duplicating len + 1 math in two different argument
lists.
Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
lib/librte_eal/common/eal_common_devargs.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index fcf3d9a3c..71753a4a0 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -233,7 +233,7 @@ int
rte_devargs_parsef(struct rte_devargs *da, const char *format, ...)
{
va_list ap;
- size_t len;
+ int len;
char *dev;
int ret;
@@ -243,15 +243,18 @@ rte_devargs_parsef(struct rte_devargs *da, const char *format, ...)
va_start(ap, format);
len = vsnprintf(NULL, 0, format, ap);
va_end(ap);
+ if (len < 0)
+ return -EINVAL;
- dev = calloc(1, len + 1);
+ len += 1;
+ dev = calloc(1, (size_t)len);
if (dev == NULL) {
RTE_LOG(ERR, EAL, "not enough memory to parse device\n");
return -ENOMEM;
}
va_start(ap, format);
- vsnprintf(dev, len + 1, format, ap);
+ vsnprintf(dev, (size_t)len, format, ap);
va_end(ap);
ret = rte_devargs_parse(da, dev);
--
2.30.0.vfs.0.2
next reply other threads:[~2021-03-15 23:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-15 23:55 Tyler Retzlaff [this message]
2021-04-19 9:21 ` 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=1615852524-3605-1-git-send-email-roretzla@linux.microsoft.com \
--to=roretzla@linux.microsoft.com \
--cc=dev@dpdk.org \
/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).