Projects
Eulaceura:Factory
iSulad
_service:obs_scm:0078-allow-env-variable-has-an...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:0078-allow-env-variable-has-an-empty-value.patch of Package iSulad
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
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2