From: Tyler Retzlaff Date: Mon, 15 Mar 2021 23:55:24 +0000 (-0700) Subject: eal: check vsnprintf failure in devargs parsing X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=e8eb80e8bfe7e0eef2c3a55cb9a4ee7c9ba12b4c;p=dpdk.git eal: check vsnprintf failure in devargs parsing 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 --- diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index e40b91ea66..4b5be80328 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -242,7 +242,7 @@ int rte_devargs_parsef(struct rte_devargs *da, const char *format, ...) { va_list ap; - size_t len; + int len; char *dev; int ret; @@ -252,15 +252,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);