From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id ACB4245594;
	Fri,  5 Jul 2024 11:34:50 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id CA3DA42F21;
	Fri,  5 Jul 2024 11:34:46 +0200 (CEST)
Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191])
 by mails.dpdk.org (Postfix) with ESMTP id E573B42ED0
 for <dev@dpdk.org>; Fri,  5 Jul 2024 11:34:43 +0200 (CEST)
Received: from mail.maildlp.com (unknown [172.19.163.17])
 by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WFpFd67hDz1HDyG;
 Fri,  5 Jul 2024 17:32:21 +0800 (CST)
Received: from dggpeml500024.china.huawei.com (unknown [7.185.36.10])
 by mail.maildlp.com (Postfix) with ESMTPS id 1F2911A0188;
 Fri,  5 Jul 2024 17:34:42 +0800 (CST)
Received: from localhost.localdomain (10.50.165.33) by
 dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.1.2507.39; Fri, 5 Jul 2024 17:34:41 +0800
From: Chengwen Feng <fengchengwen@huawei.com>
To: <thomas@monjalon.net>
CC: <dev@dpdk.org>, <cristian.dumitrescu@intel.com>,
 <stephen@networkplumber.org>, <david.marchand@redhat.com>
Subject: [PATCH v2 3/4] cfgfile: verify add section and entry result
Date: Fri, 5 Jul 2024 09:31:14 +0000
Message-ID: <20240705093115.4437-4-fengchengwen@huawei.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20240705093115.4437-1-fengchengwen@huawei.com>
References: <20240220035840.32978-1-fengchengwen@huawei.com>
 <20240705093115.4437-1-fengchengwen@huawei.com>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [10.50.165.33]
X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To
 dggpeml500024.china.huawei.com (7.185.36.10)
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

The rte_cfgfile_add_section() and _add_entry()'s result were not
verified, so that potential errors may not be detected.

This commit adds the verification.

Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/cfgfile/rte_cfgfile.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/lib/cfgfile/rte_cfgfile.c b/lib/cfgfile/rte_cfgfile.c
index 97a399635e..3033cff4a4 100644
--- a/lib/cfgfile/rte_cfgfile.c
+++ b/lib/cfgfile/rte_cfgfile.c
@@ -182,6 +182,7 @@ rte_cfgfile_load_with_params(const char *filename, int flags,
 	char buffer[CFG_NAME_LEN + CFG_VALUE_LEN + 4];
 	int lineno = 0;
 	struct rte_cfgfile *cfg;
+	int ret;
 
 	if (rte_cfgfile_check_params(params))
 		return NULL;
@@ -226,7 +227,9 @@ rte_cfgfile_load_with_params(const char *filename, int flags,
 			*end = '\0';
 			_strip(&buffer[1], end - &buffer[1]);
 
-			rte_cfgfile_add_section(cfg, &buffer[1]);
+			ret = rte_cfgfile_add_section(cfg, &buffer[1]);
+			if (ret != 0)
+				goto error1;
 		} else {
 			/* key and value line */
 			char *split[2] = {NULL};
@@ -261,8 +264,10 @@ rte_cfgfile_load_with_params(const char *filename, int flags,
 			if (cfg->num_sections == 0)
 				goto error1;
 
-			_add_entry(&cfg->sections[cfg->num_sections - 1],
-					split[0], split[1]);
+			ret = _add_entry(&cfg->sections[cfg->num_sections - 1],
+					 split[0], split[1]);
+			if (ret != 0)
+				goto error1;
 		}
 	}
 	fclose(f);
@@ -277,6 +282,7 @@ struct rte_cfgfile *
 rte_cfgfile_create(int flags)
 {
 	int i;
+	int ret;
 	struct rte_cfgfile *cfg;
 
 	/* future proof flags usage */
@@ -310,8 +316,11 @@ rte_cfgfile_create(int flags)
 		cfg->sections[i].allocated_entries = CFG_ALLOC_ENTRY_BATCH;
 	}
 
-	if (flags & CFG_FLAG_GLOBAL_SECTION)
-		rte_cfgfile_add_section(cfg, "GLOBAL");
+	if (flags & CFG_FLAG_GLOBAL_SECTION) {
+		ret = rte_cfgfile_add_section(cfg, "GLOBAL");
+		if (ret != 0)
+			goto error1;
+	}
 
 	return cfg;
 error1:
-- 
2.17.1