]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/env-util: Allow newlines in values of environment variables
authorFilipe Brandenburger <filbranden@google.com>
Fri, 16 Mar 2018 20:41:54 +0000 (13:41 -0700)
committerFilipe Brandenburger <filbranden@google.com>
Fri, 16 Mar 2018 20:45:03 +0000 (13:45 -0700)
They are allowed by the shell and the EnvironmentFile parsing passes
them through, so we should just accept them, same as we accept tabs.

src/basic/env-util.c
src/test/test-env-util.c

index 0b1d086394eb9a59abf40cb65ab56a1616d7e043..a44bb32a82c6b0835bb1b260d912215fb209fa4e 100644 (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
index b1e69d4a5a94d5b74f00e5542d81b8cd76369655..e212e37b214603100f46b59a079231301b446c45 100644 (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="));