From: Filipe Brandenburger Date: Fri, 16 Mar 2018 20:41:54 +0000 (-0700) Subject: basic/env-util: Allow newlines in values of environment variables X-Git-Tag: v239~540^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b4346b9a77bc6129dd3e73db0ea41e3ccd2b763b;p=thirdparty%2Fsystemd.git basic/env-util: Allow newlines in values of environment variables They are allowed by the shell and the EnvironmentFile parsing passes them through, so we should just accept them, same as we accept tabs. --- diff --git a/src/basic/env-util.c b/src/basic/env-util.c index 0b1d086394e..a44bb32a82c 100644 --- a/src/basic/env-util.c +++ b/src/basic/env-util.c @@ -84,9 +84,9 @@ bool env_value_is_valid(const char *e) { if (!utf8_is_valid(e)) return false; - /* bash allows tabs in environment variables, and so should - * we */ - if (string_has_cc(e, "\t")) + /* bash allows tabs and newlines in environment variables, and so + * should we */ + if (string_has_cc(e, "\t\n")) return false; /* POSIX says the overall size of the environment block cannot diff --git a/src/test/test-env-util.c b/src/test/test-env-util.c index b1e69d4a5a9..e212e37b214 100644 --- a/src/test/test-env-util.c +++ b/src/test/test-env-util.c @@ -277,8 +277,9 @@ static void test_env_clean(void) { 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); + assert_se(streq(e[4], "xyz=xyz\n")); + assert_se(streq(e[5], "another=final one")); + assert_se(e[6] == NULL); } static void test_env_name_is_valid(void) { @@ -297,6 +298,8 @@ static void test_env_value_is_valid(void) { assert_se(env_value_is_valid("")); assert_se(env_value_is_valid("głąb kapuściany")); assert_se(env_value_is_valid("printf \"\\x1b]0;\\x07\"")); + assert_se(env_value_is_valid("tab\tcharacter")); + assert_se(env_value_is_valid("new\nline")); } static void test_env_assignment_is_valid(void) { @@ -304,6 +307,8 @@ static void test_env_assignment_is_valid(void) { assert_se(env_assignment_is_valid("b=głąb kapuściany")); assert_se(env_assignment_is_valid("c=\\007\\009\\011")); assert_se(env_assignment_is_valid("e=printf \"\\x1b]0;\\x07\"")); + assert_se(env_assignment_is_valid("f=tab\tcharacter")); + assert_se(env_assignment_is_valid("g=new\nline")); assert_se(!env_assignment_is_valid("=")); assert_se(!env_assignment_is_valid("a b="));