代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/gazelle 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From db72811dedba01003a24bc85eaa6fccb65342ef0 Mon Sep 17 00:00:00 2001
From: jiangheng12 <jiangheng14@huawei.com>
Date: Fri, 24 Mar 2023 10:12:53 +0800
Subject: [PATCH] sepeate_string_to array add error args handle
---
src/common/gazelle_base_func.h | 2 +-
src/common/gazelle_opt.h | 2 +
src/common/gazelle_parse_config.c | 89 ++++++++++++++++---------------
src/lstack/core/lstack_cfg.c | 25 +++++----
src/ltran/ltran_param.c | 3 +-
5 files changed, 67 insertions(+), 54 deletions(-)
diff --git a/src/common/gazelle_base_func.h b/src/common/gazelle_base_func.h
index 22d7a7f..d21ef5f 100644
--- a/src/common/gazelle_base_func.h
+++ b/src/common/gazelle_base_func.h
@@ -28,7 +28,7 @@
#define NODE_ENTRY(node, type, member) \
((type*)((char*)(node) - (size_t)&((type*)0)->member))
-int32_t separate_str_to_array(char *args, uint32_t *array, int32_t array_size);
+int32_t separate_str_to_array(char *args, uint32_t *array, int32_t array_size, int32_t max_value);
int32_t check_and_set_run_dir(void);
diff --git a/src/common/gazelle_opt.h b/src/common/gazelle_opt.h
index fe0483b..4420ba4 100644
--- a/src/common/gazelle_opt.h
+++ b/src/common/gazelle_opt.h
@@ -88,6 +88,8 @@
#define GAZELLE_PRIMARY_START_PATH "/var/run/gazelle/gazelle_primary"
#define GAZELLE_FILE_PERMISSION 0700
+#define GAZELLE_MAX_PORTS_VALUE (UINT16_MAX - 1)
+
#define SEND_TIME_WAIT_NS 20000
#define SECOND_NSECOND 1000000000
diff --git a/src/common/gazelle_parse_config.c b/src/common/gazelle_parse_config.c
index fc286d9..a2bdde1 100644
--- a/src/common/gazelle_parse_config.c
+++ b/src/common/gazelle_parse_config.c
@@ -31,58 +31,63 @@
#define COMMON_INFO(fmt, ...) LSTACK_LOG(INFO, LSTACK, fmt, ##__VA_ARGS__)
#endif
-static int32_t parse_str_data(char *args, uint32_t *array, int32_t array_size)
+int32_t separate_str_to_array(char *args, uint32_t *array, int32_t array_size, int32_t max_value)
{
- const char *delim = "-";
- char *elem = NULL;
- char *next_token = NULL;
- char *endptr = NULL;
- int32_t cnt = 0;
- int64_t start, end;
+ uint32_t count = 0;
+ char *end = NULL;
+ int32_t min, max;
+ int32_t idx;
- elem = strtok_s(args, delim, &next_token);
- start = strtol(elem, &endptr, 0);
- if (endptr == elem) {
- return cnt;
+ for (idx = 0; idx < array_size; idx++) {
+ array[idx] = 0;
}
- elem = strtok_s(NULL, delim, &next_token);
- if (elem == NULL) {
- /* just a single data */
- array[cnt++] = (uint32_t)start;
- return cnt;
- }
- end = strtol(elem, &endptr, 0);
- if (endptr == elem) {
- array[cnt++] = start;
- return cnt;
+ while (isblank(*args)) {
+ args++;
}
- for (int64_t i = start; i <= end && cnt < array_size; i++) {
- if (i < 0 || i > UINT_MAX) {
- break;
+ min = array_size;
+ do {
+ while (isblank(*args)) {
+ args++;
}
- array[cnt++] = (uint32_t)i;
- }
-
- return cnt;
-}
-
-/* support '-' and ',' */
-int32_t separate_str_to_array(char *args, uint32_t *array, int32_t array_size)
-{
- const char *delim = ",";
- char *elem = NULL;
- char *next_token = NULL;
- int32_t cnt = 0;
+ if (*args == '\0') {
+ return -1;
+ }
+ errno = 0;
+ idx = strtol(args, &end, 10); /* 10: decimal */
+ if (errno || end == NULL) {
+ return -1;
+ }
+ if (idx < 0 || idx >= max_value) {
+ return -1;
+ }
+ while (isblank(*end)) {
+ end++;
+ }
+ if (*end == '-') {
+ min = idx;
+ } else if ((*end == ',') || (*end == '\0') || (*end == '\n')) {
+ max = idx;
+ if (min == array_size) {
+ min = idx;
+ }
+ for (idx = min; idx <= max; idx++) {
+ array[count] = idx;
+ count++;
+ }
+ min = array_size;
+ } else {
+ return -1;
+ }
+ args = end + 1;
+ } while (*end != '\0' && *end != '\n');
- elem = strtok_s(args, delim, &next_token);
- while (elem != NULL && cnt < array_size) {
- cnt += parse_str_data(elem, &array[cnt], array_size - cnt);
- elem = strtok_s(NULL, delim, &next_token);
+ if (count == 0) {
+ return -1;
}
- return cnt;
+ return count;
}
int32_t check_and_set_run_dir(void)
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
index bed102e..f033fa7 100644
--- a/src/lstack/core/lstack_cfg.c
+++ b/src/lstack/core/lstack_cfg.c
@@ -309,7 +309,7 @@ static int32_t parse_stack_cpu_number(void)
}
char *tmp_arg = strdup(args);
- int32_t cnt = separate_str_to_array(tmp_arg, g_config_params.cpus, CFG_MAX_CPUS);
+ 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) {
return -EINVAL;
@@ -342,7 +342,7 @@ static int32_t parse_stack_cpu_number(void)
}
char *tmp_arg_send = strdup(args);
- int32_t cnt = separate_str_to_array(tmp_arg_send, g_config_params.send_cpus, CFG_MAX_CPUS);
+ 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);
// recv_num_cpus
@@ -368,15 +368,15 @@ static int32_t parse_stack_cpu_number(void)
}
char *tmp_arg_recv = strdup(args);
- cnt = separate_str_to_array(tmp_arg_recv, g_config_params.recv_cpus, CFG_MAX_CPUS);
+ 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);
- if (cnt <= 0 || cnt > CFG_MAX_CPUS / 2) {
+ if (send_cpu_cnt <= 0 || send_cpu_cnt > CFG_MAX_CPUS / 2 || send_cpu_cnt != recv_cpu_cnt) {
return -EINVAL;
}
- g_config_params.num_cpu = cnt;
- g_config_params.num_queue = (uint16_t)cnt * 2;
+ g_config_params.num_cpu = send_cpu_cnt;
+ g_config_params.num_queue = (uint16_t)send_cpu_cnt * 2;
g_config_params.tot_queue_num = g_config_params.num_queue;
}
@@ -407,7 +407,7 @@ static int32_t numa_to_cpusnum(unsigned socket_id, uint32_t *cpulist, int32_t nu
return -1;
}
- int32_t count = separate_str_to_array(strbuf, cpulist, num);
+ int32_t count = separate_str_to_array(strbuf, cpulist, num, CFG_MAX_CPUS);
return count;
}
@@ -492,9 +492,14 @@ static int32_t gazelle_parse_socket_mem(const char *arg, struct secondary_attach
return -1;
}
- int32_t count = separate_str_to_array(socket_mem, sec_attach_arg->socket_per_size, GAZELLE_MAX_NUMA_NODES);
+ int32_t count = separate_str_to_array(socket_mem, sec_attach_arg->socket_per_size, GAZELLE_MAX_NUMA_NODES, GAZELLE_MAX_PORTS_VALUE);
+
+ if (count < 0) {
+ return -1;
+ }
+
for (uint32_t i = 0; i < count; i++) {
- mem_size += sec_attach_arg->socket_per_size[count];
+ mem_size += sec_attach_arg->socket_per_size[i];
}
mem_size *= 1024LL;
mem_size *= 1024LL;
@@ -993,7 +998,7 @@ static int32_t parse_process_numa(void)
return 0;
}
- ret = separate_str_to_array((char *)args, g_config_params.process_numa, PROTOCOL_STACK_MAX);
+ ret = separate_str_to_array((char *)args, g_config_params.process_numa, PROTOCOL_STACK_MAX, GAZELLE_MAX_NUMA_NODES);
if (ret <= 0) {
return -EINVAL;
}
diff --git a/src/ltran/ltran_param.c b/src/ltran/ltran_param.c
index 1b9d82b..7cf3423 100644
--- a/src/ltran/ltran_param.c
+++ b/src/ltran/ltran_param.c
@@ -339,7 +339,8 @@ static int32_t parse_bond_ports(const config_t *config, const char *key, struct
return GAZELLE_ERR;
}
- ltran_config->bond.port_num = separate_str_to_array(port_str, ltran_config->bond.portmask, GAZELLE_MAX_BOND_NUM);
+ ltran_config->bond.port_num = separate_str_to_array(port_str, ltran_config->bond.portmask, GAZELLE_MAX_BOND_NUM, GAZELLE_MAX_PORTS_VALUE);
+
if (ltran_config->bond.port_num > GAZELLE_MAX_BOND_NUM) {
free(port_str);
gazelle_set_errno(GAZELLE_ERANGE);
--
2.23.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。