Skip to content

Commit

Permalink
Merge pull request #2204 from pi-hole/fix/envvars_splitting
Browse files Browse the repository at this point in the history
 Fix parsing of envvars with more than one =
  • Loading branch information
DL6ER authored Feb 19, 2025
2 parents 093c921 + 099eb1c commit f68a6bb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/config/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit f68a6bb

Please sign in to comment.