Skip to contentSkip to conversation

eal: check vsnprintf failure and return -EINVAL

PATCH Applied Tyler Retzlaff 2 participants 2 messages Mar 15, 2021 – Apr 19, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal: check vsnprintf failure and return -EINVAL

Check for failure, while here just increment len once after checking for failure instead of duplicating len + 1 math in two different argument lists.

---
 lib/librte_eal/common/eal_common_devargs.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
lib/librte_eal/common/eal_common_devargs.c +6 -3
index fcf3d9a3c..71753a4a0 100644
@@ -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);
Signature · 1 line
2.30.0.vfs.0.2
#1 lore raw

16/03/2021 00:55, Tyler Retzlaff:

Quoted 5 lines

Check for failure, while here just increment len once after checking for failure instead of duplicating len + 1 math in two different argument lists.

Applied, thanks