]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: fix env expansion for strings leading with two dollar signs
authorMichal Schmidt <mschmidt@redhat.com>
Wed, 7 Oct 2015 12:40:44 +0000 (14:40 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Wed, 7 Oct 2015 12:43:55 +0000 (14:43 +0200)
The way to escape a literal dollar sign is to write "$$". But this does
not work right if it's at the beginning of the argument. Fix it.

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

index 4804a67f914e5f19a0ebbedda296df30d9ca20c5..ecb2192c4d79ea5b8b877a689421241bc1ea9058 100644 (file)
@@ -541,7 +541,7 @@ char **replace_env_argv(char **argv, char **env) {
         STRV_FOREACH(i, argv) {
 
                 /* If $FOO appears as single word, replace it by the split up variable */
-                if ((*i)[0] == '$' && (*i)[1] != '{') {
+                if ((*i)[0] == '$' && (*i)[1] != '{' && (*i)[1] != '$') {
                         char *e;
                         char **w, **m = NULL;
                         unsigned q;
index 2e28c0c49bcd97d0566835a33aa771fca74602a8..110223f3b85d63920f8be4471d6d71df376fb37b 100644 (file)
@@ -118,6 +118,8 @@ static void test_replace_env_arg(void) {
                 "$FOO$FOO",
                 "${FOO}${BAR}",
                 "${FOO",
+                "FOO$$${FOO}",
+                "$$FOO${FOO}",
                 NULL
         };
         _cleanup_strv_free_ char **r = NULL;
@@ -133,7 +135,9 @@ static void test_replace_env_arg(void) {
         assert_se(streq(r[6], "BAR"));
         assert_se(streq(r[7], "BAR BARwaldo"));
         assert_se(streq(r[8], "${FOO"));
-        assert_se(strv_length(r) == 9);
+        assert_se(streq(r[9], "FOO$BAR BAR"));
+        assert_se(streq(r[10], "$FOOBAR BAR"));
+        assert_se(strv_length(r) == 11);
 }
 
 static void test_env_clean(void) {