]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/env-file: also change to state PRE_KEY if we see NEWLINE in state COMMENT_ESCAPE
authorlicunlong <licunlong1@huawei.com>
Mon, 19 Jun 2023 13:56:33 +0000 (21:56 +0800)
committerlicunlong <licunlong1@huawei.com>
Tue, 20 Jun 2023 06:42:44 +0000 (14:42 +0800)
When we see a "\" in COMMENT state, we change the state to COMMENT_ESCAPE. When we got
a new character, we reset the state to COMMENT, but this character is not dispatched.
Usually the character is NEWLINE, if so we will stay in COMMENT state until we find
the next NEWLINE.

fix: https://github.com/systemd/systemd/issues/27975

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

index 58d7b3ec359d5a949be7652807980e248d1c3641..eb5e64049493f050c50f98796ec76aec0d93a856 100644 (file)
@@ -243,7 +243,13 @@ static int parse_env_file_internal(
                         break;
 
                 case COMMENT_ESCAPE:
-                        state = COMMENT;
+                        log_debug("The line which doesn't begin with \";\" or \"#\", but follows a comment" \
+                                  " line trailing with escape is now treated as a non comment line since v254.");
+                        if (strchr(NEWLINE, c)) {
+                                state = PRE_KEY;
+                                line++;
+                        } else
+                                state = COMMENT;
                         break;
                 }
         }
index c8ec0e2278aa449d86c756d197e272cd5e623ba5..49f108945b1bb631eedb49d4d542c8da7ee89b38 100644 (file)
 #define env_file_3 \
         "#SPAMD_ARGS=\"-d --socketpath=/var/lib/bulwark/spamd \\\n" \
         "#--nouser-config                                     \\\n" \
-        "normal=line                                          \\\n" \
+        "normal1=line\\\n"                                           \
+        "111\n"                                                     \
         ";normal=ignored                                      \\\n" \
-        "normal_ignored                                       \\\n" \
+        "normal2=line222\n"                                          \
         "normal ignored                                       \\\n"
 
 #define env_file_4                              \
@@ -89,7 +90,9 @@ TEST(load_env_file_3) {
 
         _cleanup_strv_free_ char **data = NULL;
         assert_se(load_env_file(NULL, name, &data) == 0);
-        assert_se(data == NULL);
+        assert_se(streq(data[0], "normal1=line111"));
+        assert_se(streq(data[1], "normal2=line222"));
+        assert_se(data[2] == NULL);
 }
 
 TEST(load_env_file_4) {