diff options
author | Ben Hutchings <ben@decadent.org.uk> | 2016-01-22 20:13:35 +0000 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2016-01-28 15:34:45 +0000 |
commit | 6326ab374ede4fff1e8019a50d4b9854b8db7625 (patch) | |
tree | 759b87d914c7b5d92b911896a1f4a4614dadd282 /src | |
parent | 78bc7d9c835404ad1b5d2eb26de390bd45e26d2a (diff) | |
download | odhcp6c-6326ab374ede4fff1e8019a50d4b9854b8db7625.tar.gz |
Fix script environment variable setting for empty lists
When setting an environment variable as a space-separated list, and
the list is empty, we must not delete the '=' before the value.
In practice putenv() is likely to discard the invalid string, leaving
the variable unset, but this is not guaranteed.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'src')
-rw-r--r-- | src/script.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/script.c b/src/script.c index 3579331..1533510 100644 --- a/src/script.c +++ b/src/script.c @@ -105,7 +105,9 @@ static void ipv6_to_env(const char *name, buf_len += strlen(&buf[buf_len]); buf[buf_len++] = ' '; } - buf[buf_len - 1] = '\0'; + if (buf[buf_len - 1] == ' ') + buf_len--; + buf[buf_len] = '\0'; putenv(buf); } @@ -126,7 +128,9 @@ static void fqdn_to_env(const char *name, const uint8_t *fqdn, size_t len) buf_len += strlen(&buf[buf_len]); buf[buf_len++] = ' '; } - buf[buf_len - 1] = '\0'; + if (buf[buf_len - 1] == ' ') + buf_len--; + buf[buf_len] = '\0'; putenv(buf); } @@ -201,7 +205,9 @@ static void entry_to_env(const char *name, const void *data, size_t len, enum en buf[buf_len++] = ' '; } - buf[buf_len - 1] = '\0'; + if (buf[buf_len - 1] == ' ') + buf_len--; + buf[buf_len] = '\0'; putenv(buf); } @@ -220,7 +226,9 @@ static void search_to_env(const char *name, const uint8_t *start, size_t len) *c++ = ' '; } - c[-1] = '\0'; + if (c[-1] == ' ') + c--; + *c = '\0'; putenv(buf); } |