From 099eb1ceb9c83bfd362703cdab6bac13874f38a4 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 19 Feb 2025 17:16:38 +0100 Subject: [PATCH] Ensure we do not split too often at '=' while processing environment variables Signed-off-by: DL6ER --- src/config/env.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/config/env.c b/src/config/env.c index 0981c6195..908099e00 100644 --- a/src/config/env.c +++ b/src/config/env.c @@ -55,14 +55,21 @@ void getEnvVars(void) // Split key and value using strtok_r char *saveptr = NULL; char *key = strtok_r(env_copy, "=", &saveptr); - char *value = strtok_r(NULL, "=", &saveptr); // Log warning if value is missing - if(value == NULL) + char *value; + if(strlen(*env) <= strlen(key) + 1) { log_warn("Environment variable %s has no value, substituting with empty string", key); value = (char*)""; } + else + { + // The entire string *after* the key + 1 (for + // the '=') is the value + value = *env + strlen(key) + 1; + } + log_debug(DEBUG_CONFIG, "ENV \"%s\" = \"%s\"", key, value); // Add to list struct env_item *new_item = calloc(1, sizeof(struct env_item));