1 Star 0 Fork 32

yc555/gazelle_1

forked from src-openEuler/gazelle 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0094-CFG-fix-check-func-strdup-return-value-is-NULL.patch 4.69 KB
一键复制 编辑 原始数据 按行查看 历史
From 43985056c5446c0ad45acb2309165543bd8e15e1 Mon Sep 17 00:00:00 2001
From: yinbin <yinbin8@huawei.com>
Date: Fri, 22 Dec 2023 15:42:40 +0800
Subject: [PATCH] CFG:fix check func strdup return value is NULL
---
src/lstack/core/lstack_cfg.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
index 6324c97..6e97c96 100644
--- a/src/lstack/core/lstack_cfg.c
+++ b/src/lstack/core/lstack_cfg.c
@@ -145,6 +145,15 @@ static struct config_vector_t g_config_tbl[] = {
{ NULL, NULL }
};
+static char* strdup_assert_return(const char* str)
+{
+ char* result = strdup(str);
+ if (result == NULL) {
+ LSTACK_EXIT(1, "strdup_assert_return failed, func strdup return NULL!\n");
+ }
+ return result;
+}
+
struct cfg_params *get_global_cfg_params(void)
{
return &g_config_params;
@@ -336,15 +345,15 @@ static int32_t parse_stack_cpu_number(void)
if (!have_corelist_arg(g_config_params.dpdk_argc, g_config_params.dpdk_argv)) {
int32_t idx = get_param_idx(g_config_params.dpdk_argc, g_config_params.dpdk_argv, OPT_BIND_CORELIST);
if (idx < 0) {
- g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup(OPT_BIND_CORELIST);
+ g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(OPT_BIND_CORELIST);
g_config_params.dpdk_argc++;
- g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup(args);
+ g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(args);
g_config_params.dpdk_argc++;
}
}
- char *tmp_arg = strdup(args);
+ char *tmp_arg = strdup_assert_return(args);
int32_t cnt = separate_str_to_array(tmp_arg, g_config_params.cpus, CFG_MAX_CPUS, CFG_MAX_CPUS);
free(tmp_arg);
if (cnt <= 0 || cnt > CFG_MAX_CPUS) {
@@ -369,15 +378,15 @@ static int32_t parse_stack_cpu_number(void)
if (!have_corelist_arg(g_config_params.dpdk_argc, g_config_params.dpdk_argv)) {
int32_t idx = get_param_idx(g_config_params.dpdk_argc, g_config_params.dpdk_argv, OPT_BIND_CORELIST);
if (idx < 0) {
- g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup(OPT_BIND_CORELIST);
+ g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(OPT_BIND_CORELIST);
g_config_params.dpdk_argc++;
- g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup(args);
+ g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(args);
g_config_params.dpdk_argc++;
}
}
- char *tmp_arg_send = strdup(args);
+ char *tmp_arg_send = strdup_assert_return(args);
int32_t send_cpu_cnt = separate_str_to_array(tmp_arg_send, g_config_params.send_cpus,
CFG_MAX_CPUS, CFG_MAX_CPUS);
free(tmp_arg_send);
@@ -396,15 +405,15 @@ static int32_t parse_stack_cpu_number(void)
if (!have_corelist_arg(g_config_params.dpdk_argc, g_config_params.dpdk_argv)) {
int32_t idx = get_param_idx(g_config_params.dpdk_argc, g_config_params.dpdk_argv, OPT_BIND_CORELIST);
if (idx < 0) {
- g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup(OPT_BIND_CORELIST);
+ g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(OPT_BIND_CORELIST);
g_config_params.dpdk_argc++;
- g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup(args);
+ g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(args);
g_config_params.dpdk_argc++;
}
}
- char *tmp_arg_recv = strdup(args);
+ char *tmp_arg_recv = strdup_assert_return(args);
int32_t recv_cpu_cnt = separate_str_to_array(tmp_arg_recv, g_config_params.recv_cpus,
CFG_MAX_CPUS, CFG_MAX_CPUS);
free(tmp_arg_recv);
@@ -450,7 +459,7 @@ static int32_t parse_app_exclude_cpus(void)
return -EINVAL;
}
- tmp_arg = strdup(args);
+ tmp_arg = strdup_assert_return(args);
cnt = separate_str_to_array(tmp_arg, g_config_params.app_exclude_cpus, CFG_MAX_CPUS, CFG_MAX_CPUS);
free(tmp_arg);
if (cnt <= 0 || cnt > CFG_MAX_CPUS) {
@@ -1176,7 +1185,7 @@ static int32_t parse_bond_slave_mac(void)
}
int32_t k = 0;
- char *bond_slave_mac_tmp = strdup(bond_slave_mac);
+ char *bond_slave_mac_tmp = strdup_assert_return(bond_slave_mac);
char *tmp = NULL;
const char *delim = ";";
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangchen555/gazelle_1.git
git@gitee.com:yangchen555/gazelle_1.git
yangchen555
gazelle_1
gazelle_1
master

搜索帮助