diff options
author | CoprDistGit <infra@openeuler.org> | 2024-09-03 03:24:28 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2024-09-03 03:24:28 +0000 |
commit | e45819fcb4a96649a4030db7684f140d5ca46735 (patch) | |
tree | 544dac3e30a0448eabdc50add41aa3a18982d9f1 /0078-allow-env-variable-has-an-empty-value.patch | |
parent | 1a71e3afebb4b43be63949dcc8e882fe7643f13b (diff) |
automatic import of iSuladopeneuler24.03_LTS
Diffstat (limited to '0078-allow-env-variable-has-an-empty-value.patch')
-rw-r--r-- | 0078-allow-env-variable-has-an-empty-value.patch | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/0078-allow-env-variable-has-an-empty-value.patch b/0078-allow-env-variable-has-an-empty-value.patch new file mode 100644 index 0000000..213a996 --- /dev/null +++ b/0078-allow-env-variable-has-an-empty-value.patch @@ -0,0 +1,69 @@ +From f0212d54afc695b2039f09456b10c47f8edaf2de Mon Sep 17 00:00:00 2001 +From: jikai <jikai11@huawei.com> +Date: Sat, 27 Apr 2024 14:32:19 +0800 +Subject: [PATCH 78/78] allow env variable has an empty value + +Signed-off-by: jikai <jikai11@huawei.com> +--- + src/daemon/modules/spec/specs_extend.c | 10 ++++++---- + src/utils/cutils/utils_string.c | 3 +++ + 2 files changed, 9 insertions(+), 4 deletions(-) + +diff --git a/src/daemon/modules/spec/specs_extend.c b/src/daemon/modules/spec/specs_extend.c +index 199cba54..8cad2cbe 100644 +--- a/src/daemon/modules/spec/specs_extend.c ++++ b/src/daemon/modules/spec/specs_extend.c +@@ -195,6 +195,7 @@ static int generate_env_map_from_file(FILE *fp, json_map_string_string *env_map) + char *pline = NULL; + size_t length = 0; + char *saveptr = NULL; ++ char empty_str[1] = {'\0'}; + + while (getline(&pline, &length, fp) != -1) { + util_trim_newline(pline); +@@ -204,7 +205,9 @@ static int generate_env_map_from_file(FILE *fp, json_map_string_string *env_map) + } + key = strtok_r(pline, "=", &saveptr); + value = strtok_r(NULL, "=", &saveptr); +- if (key != NULL && value != NULL) { ++ // value of an env varible is allowed to be empty ++ value = value ? value : empty_str; ++ if (key != NULL) { + key = util_trim_space(key); + value = util_trim_space(value); + if ((size_t)(MAX_BUFFER_SIZE - 1) - strlen(key) < strlen(value)) { +@@ -291,15 +294,14 @@ static int check_env_need_append(const oci_runtime_spec *oci_spec, const char *e + { + size_t i = 0; + char *key = NULL; +- char *value = NULL; + char *saveptr = NULL; + + for (i = 0; i < oci_spec->process->env_len; i++) { + char *tmp_env = NULL; + tmp_env = util_strdup_s(oci_spec->process->env[i]); + key = strtok_r(tmp_env, "=", &saveptr); +- value = strtok_r(NULL, "=", &saveptr); +- if (key == NULL || value == NULL) { ++ // value of an env varible is allowed to be empty ++ if (key == NULL) { + ERROR("Bad env format"); + free(tmp_env); + tmp_env = NULL; +diff --git a/src/utils/cutils/utils_string.c b/src/utils/cutils/utils_string.c +index 64afb570..11a65f19 100644 +--- a/src/utils/cutils/utils_string.c ++++ b/src/utils/cutils/utils_string.c +@@ -534,6 +534,9 @@ static char *util_left_trim_space(char *str) + { + char *begin = str; + char *tmp = str; ++ if (strlen(str) == 0) { ++ return str; ++ } + while (isspace(*begin)) { + begin++; + } +-- +2.25.1 + |