diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-02-11 03:46:08 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-02-11 03:54:50 +0100 |
commit | 4d1a69043862ed979642f5688097160355d4cc81 (patch) | |
tree | deac099c3b4da6740cedac9af10913981303f78b /src/test | |
parent | c62c294fd521e5b65bb52f831773916bbc4cd90a (diff) |
env: considerably beef up environment cleaning logic
Now, actually check if the environment variable names and values used
are valid, before accepting them. With this in place are at some places
more rigid than POSIX, and less rigid at others. For example, this code
allows lower-case environment variables (which POSIX suggests not to
use), but it will not allow non-UTF8 variable values.
All in all this should be a good middle ground of what to allow and what
not to allow as environment variables.
(This also splits out all environment related calls into env-util.[ch])
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-env-replace.c | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/src/test/test-env-replace.c b/src/test/test-env-replace.c index 2da3845354..b8747db681 100644 --- a/src/test/test-env-replace.c +++ b/src/test/test-env-replace.c @@ -24,6 +24,7 @@ #include "util.h" #include "strv.h" +#include "env-util.h" static void test_strv_env_delete(void) { _cleanup_strv_free_ char **a = NULL, **b = NULL, **c = NULL, **d = NULL; @@ -81,10 +82,12 @@ static void test_strv_env_merge(void) { assert(strv_length(r) == 6); strv_env_clean(r); - assert(streq(r[0], "PIEP")); - assert(streq(r[1], "SCHLUMPF=SMURFF")); - assert(streq(r[2], "NANANANA=YES")); - assert(strv_length(r) == 3); + assert(streq(r[0], "FOO=")); + assert(streq(r[1], "WALDO=")); + assert(streq(r[2], "SCHLUMPF=SMURFF")); + assert(streq(r[3], "PIEP=")); + assert(streq(r[4], "NANANANA=YES")); + assert(strv_length(r) == 5); } static void test_replace_env_arg(void) { @@ -145,6 +148,38 @@ static void test_normalize_env_assignment(void) { test_one_normalize(" ' xyz' = 'bar ' ", "' xyz'=bar "); } +static void test_env_clean(void) { + + _cleanup_strv_free_ char **e; + + e = strv_new("FOOBAR=WALDO", + "FOOBAR=WALDO", + "FOOBAR", + "F", + "X=", + "F=F", + "=", + "=F", + "", + "0000=000", + "äöüß=abcd", + "abcd=äöüß", + "xyz\n=xyz", + "xyz=xyz\n", + "another=one", + "another=final one", + NULL); + + assert_se(strv_env_clean(e)); + + assert_se(streq(e[0], "FOOBAR=WALDO")); + assert_se(streq(e[1], "X=")); + assert_se(streq(e[2], "F=F")); + assert_se(streq(e[3], "abcd=äöüß")); + assert_se(streq(e[4], "another=final one")); + assert_se(e[5] == NULL); +} + int main(int argc, char *argv[]) { test_strv_env_delete(); test_strv_env_unset(); @@ -152,6 +187,7 @@ int main(int argc, char *argv[]) { test_strv_env_merge(); test_replace_env_arg(); test_normalize_env_assignment(); + test_env_clean(); return 0; } |