From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4FE7CA054F; Tue, 16 Mar 2021 00:55:33 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C78AA4069F; Tue, 16 Mar 2021 00:55:32 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 400F040042 for ; Tue, 16 Mar 2021 00:55:31 +0100 (CET) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 60B7D209B8AE for ; Mon, 15 Mar 2021 16:55:30 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 60B7D209B8AE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1615852530; bh=lwCfUSdNfErBST39sSUfwCfSURreEgUgV6inzdjBCqw=; h=From:To:Subject:Date:From; b=O1+IaxdSPpE7CFgWd0/AlpfoKnjiVp0UUKknLIpk+R4jaBwmFAYUD0dGcZgi9P+EZ Oa5yzAwZfMSNKnUBh4u3n505OdtyUqeoyg9ewDYQCEbXzVO2CxUCkjNvBsfWCBfe15 0dE436rQMvSnabSusmNXRn7W2zzjjdWTAmkAZX4k= From: Tyler Retzlaff To: dev@dpdk.org Date: Mon, 15 Mar 2021 16:55:24 -0700 Message-Id: <1615852524-3605-1-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 Subject: [dpdk-dev] [PATCH] eal: check vsnprintf failure and return -EINVAL X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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