85 lines
2.7 KiB
Diff
85 lines
2.7 KiB
Diff
|
|
From 9911948a5806c6641d8c6a7ffe7cbe82da165917 Mon Sep 17 00:00:00 2001
|
||
|
|
From: haozi007 <liuhao27@huawei.com>
|
||
|
|
Date: Mon, 22 Nov 2021 06:27:10 +0000
|
||
|
|
Subject: [PATCH 1/2] improve code for check ags
|
||
|
|
|
||
|
|
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||
|
|
---
|
||
|
|
.gitignore | 2 ++
|
||
|
|
src/api.c | 9 +++++++--
|
||
|
|
src/conf.c | 9 +++++----
|
||
|
|
3 files changed, 14 insertions(+), 6 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/.gitignore b/.gitignore
|
||
|
|
index c663504..31f4e6f 100644
|
||
|
|
--- a/.gitignore
|
||
|
|
+++ b/.gitignore
|
||
|
|
@@ -28,3 +28,5 @@ missing
|
||
|
|
|
||
|
|
**/.deps
|
||
|
|
**/.dirstamp
|
||
|
|
+
|
||
|
|
+.vscode
|
||
|
|
diff --git a/src/api.c b/src/api.c
|
||
|
|
index 52d193f..13a4ec8 100644
|
||
|
|
--- a/src/api.c
|
||
|
|
+++ b/src/api.c
|
||
|
|
@@ -114,6 +114,10 @@ static int inject_runtime_config_items(const struct network_config *orig, const
|
||
|
|
int ret = -1;
|
||
|
|
size_t i = 0;
|
||
|
|
|
||
|
|
+ if (orig->network->capabilities == NULL) {
|
||
|
|
+ return 0;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
*rt_config = clibcni_util_common_calloc_s(sizeof(cni_net_conf_runtime_config));
|
||
|
|
if (*rt_config == NULL) {
|
||
|
|
*err = clibcni_util_strdup_s("Out of memory");
|
||
|
|
@@ -182,8 +186,9 @@ static int inject_runtime_config(const struct network_config *orig, const struct
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
- if (orig->network == NULL || orig->network->capabilities == NULL) {
|
||
|
|
- return 0;
|
||
|
|
+ if (orig->network == NULL) {
|
||
|
|
+ ERROR("empty network config");
|
||
|
|
+ return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
save_conf = orig->network->runtime_config;
|
||
|
|
diff --git a/src/conf.c b/src/conf.c
|
||
|
|
index a6f3f04..d1ff3d9 100644
|
||
|
|
--- a/src/conf.c
|
||
|
|
+++ b/src/conf.c
|
||
|
|
@@ -37,13 +37,14 @@
|
||
|
|
static int do_conf_from_bytes(const char *conf_str, struct network_config *config, char **err)
|
||
|
|
{
|
||
|
|
int ret = 0;
|
||
|
|
+ int nret = 0;
|
||
|
|
parser_error jerr = NULL;
|
||
|
|
struct parser_context ctx = { OPT_PARSE_FULLKEY | OPT_GEN_SIMPLIFY, 0 };
|
||
|
|
|
||
|
|
config->network = cni_net_conf_parse_data(conf_str, &ctx, &jerr);
|
||
|
|
if (config->network == NULL) {
|
||
|
|
- ret = asprintf(err, "Error parsing configuration: %s", jerr);
|
||
|
|
- if (ret < 0) {
|
||
|
|
+ nret = asprintf(err, "Error parsing configuration: %s", jerr);
|
||
|
|
+ if (nret < 0) {
|
||
|
|
*err = clibcni_util_strdup_s("Out of memory");
|
||
|
|
}
|
||
|
|
ERROR("Error parsing configuration: %s", jerr);
|
||
|
|
@@ -51,8 +52,8 @@ static int do_conf_from_bytes(const char *conf_str, struct network_config *confi
|
||
|
|
goto out;
|
||
|
|
}
|
||
|
|
if (config->network->name != NULL && clibcni_util_validate_name(config->network->name) != 0) {
|
||
|
|
- ret = asprintf(err, "Invalid network name: %s", config->network->name);
|
||
|
|
- if (ret < 0) {
|
||
|
|
+ nret = asprintf(err, "Invalid network name: %s", config->network->name);
|
||
|
|
+ if (nret < 0) {
|
||
|
|
*err = clibcni_util_strdup_s("Out of memory");
|
||
|
|
}
|
||
|
|
ERROR("Invalid network name: %s", config->network->name);
|
||
|
|
--
|
||
|
|
2.20.1
|
||
|
|
|