1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

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.
This commit is contained in:
Filipe Brandenburger 2018-03-16 13:41:54 -07:00
parent d24e70fe8b
commit b4346b9a77
2 changed files with 10 additions and 5 deletions

View File

@ -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

View File

@ -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;<mock-chroot>\\x07<mock-chroot>\""));
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;<mock-chroot>\\x07<mock-chroot>\""));
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="));