Skip to content

Commit

Permalink
Fix script environment variable setting for empty lists
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bwhacks committed Jan 28, 2016
1 parent 78bc7d9 commit 6326ab3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/script.c
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit 6326ab3

Please sign in to comment.