Merge pull request #8471 from filbranden/envnewline1
basic/env-util: Allow newlines in values of environment variables
This commit is contained in:
commit
6f1ea95493
|
@ -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
|
||||
|
|
|
@ -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="));
|
||||
|
|
|
@ -466,7 +466,8 @@ static void test_exec_environmentfile(Manager *m) {
|
|||
"; comment2\n"
|
||||
" ; # comment3\n"
|
||||
"line without an equal\n"
|
||||
"VAR3='$word 5 6'\n";
|
||||
"VAR3='$word 5 6'\n"
|
||||
"VAR4='new\nline'\n";
|
||||
int r;
|
||||
|
||||
r = write_string_file("/tmp/test-exec_environmentfile.conf", e, WRITE_STRING_FILE_CREATE);
|
||||
|
@ -492,12 +493,14 @@ static void test_exec_passenvironment(Manager *m) {
|
|||
assert_se(setenv("VAR1", "word1 word2", 1) == 0);
|
||||
assert_se(setenv("VAR2", "word3", 1) == 0);
|
||||
assert_se(setenv("VAR3", "$word 5 6", 1) == 0);
|
||||
assert_se(setenv("VAR4", "new\nline", 1) == 0);
|
||||
test(m, "exec-passenvironment.service", 0, CLD_EXITED);
|
||||
test(m, "exec-passenvironment-repeated.service", 0, CLD_EXITED);
|
||||
test(m, "exec-passenvironment-empty.service", 0, CLD_EXITED);
|
||||
assert_se(unsetenv("VAR1") == 0);
|
||||
assert_se(unsetenv("VAR2") == 0);
|
||||
assert_se(unsetenv("VAR3") == 0);
|
||||
assert_se(unsetenv("VAR4") == 0);
|
||||
test(m, "exec-passenvironment-absent.service", 0, CLD_EXITED);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
Description=Test for EnvironmentFile
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6"'
|
||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6" && test "$$VAR4" = "new\nline"'
|
||||
Type=oneshot
|
||||
EnvironmentFile=/tmp/test-exec_environmentfile.conf
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
Description=Test for PassEnvironment with variables absent from the execution environment
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -x -c 'test "$${VAR1-unset}" = "unset" && test "$${VAR2-unset}" = "unset" && test "$${VAR3-unset}" = "unset"'
|
||||
ExecStart=/bin/sh -x -c 'test "$${VAR1-unset}" = "unset" && test "$${VAR2-unset}" = "unset" && test "$${VAR3-unset}" = "unset" && test "$${VAR4-unset}" = "unset"'
|
||||
Type=oneshot
|
||||
PassEnvironment=VAR1 VAR2 VAR3
|
||||
PassEnvironment=VAR1 VAR2 VAR3 VAR4
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Description=Test for PassEnvironment and erasing the variable list
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -x -c 'test "$${VAR1-unset}" = "unset" && test "$${VAR2-unset}" = "unset" && test "$${VAR3-unset}" = "unset"'
|
||||
ExecStart=/bin/sh -x -c 'test "$${VAR1-unset}" = "unset" && test "$${VAR2-unset}" = "unset" && test "$${VAR3-unset}" = "unset" && test "$${VAR4-unset}" = "unset"'
|
||||
Type=oneshot
|
||||
PassEnvironment=VAR1 VAR2 VAR3
|
||||
PassEnvironment=VAR1 VAR2 VAR3 VAR4
|
||||
PassEnvironment=
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
Description=Test for PassEnvironment with a variable name repeated
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6"'
|
||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6" && test "$$VAR4" = "new\nline"'
|
||||
Type=oneshot
|
||||
PassEnvironment=VAR1 VAR2
|
||||
PassEnvironment=VAR1 VAR3
|
||||
PassEnvironment=VAR1 VAR4
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
Description=Test for PassEnvironment
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6"'
|
||||
ExecStart=/bin/sh -x -c 'test "$$VAR1" = "word1 word2" && test "$$VAR2" = word3 && test "$$VAR3" = "\\$$word 5 6" && test "$$VAR4" = "new\nline"'
|
||||
Type=oneshot
|
||||
PassEnvironment=VAR1 VAR2 VAR3
|
||||
PassEnvironment=VAR1 VAR2 VAR3 VAR4
|
||||
|
|
Loading…
Reference in New Issue