diff mbox series

eal: check vsnprintf failure and return -EINVAL

Message ID 1615852524-3605-1-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Accepted
Delegated to: David Marchand
Headers show
Series eal: check vsnprintf failure and return -EINVAL | expand

Checks

Context Check Description
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance fail Performance Testing issues
ci/iol-mellanox-Functional success Functional Testing PASS
ci/iol-testing success Testing PASS
ci/github-robot success github build: passed
ci/travis-robot success travis build: passed
ci/iol-abi-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff March 15, 2021, 11:55 p.m. UTC
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(-)

Comments

Thomas Monjalon April 19, 2021, 9:21 a.m. UTC | #1
16/03/2021 00:55, Tyler Retzlaff:
> 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>

Applied, thanks
diff mbox series

Patch

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);