From cd93ec5ed2e9eaa1dfdf06e5910d46488f7dcda2 Mon Sep 17 00:00:00 2001 From: licunlong Date: Mon, 19 Jun 2023 21:56:33 +0800 Subject: [PATCH 1/2] basic/env-file: also change to state PRE_KEY if we see NEWLINE in state COMMENT_ESCAPE 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 | 8 +++++++- src/test/test-env-file.c | 9 ++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/basic/env-file.c b/src/basic/env-file.c index 58d7b3ec35..eb5e640494 100644 --- a/src/basic/env-file.c +++ b/src/basic/env-file.c @@ -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; } } diff --git a/src/test/test-env-file.c b/src/test/test-env-file.c index c8ec0e2278..49f108945b 100644 --- a/src/test/test-env-file.c +++ b/src/test/test-env-file.c @@ -31,9 +31,10 @@ #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) { From b4ff8ba077b317d402e67ff67fdccd60a860a410 Mon Sep 17 00:00:00 2001 From: licunlong Date: Tue, 20 Jun 2023 11:11:02 +0800 Subject: [PATCH 2/2] NEWS: note the incompatible change of EnvironmentFile --- NEWS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NEWS b/NEWS index a2a9aa351f..cd9792a0b6 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,12 @@ systemd System and Service Manager CHANGES WITH 254 in spe: + Announcements of Future Feature Removals and Incompatible Changes: + + * EnvironmentFile now treats the line following a comment line trailing + with escape as a non comment line. For details, see: + https://github.com/systemd/systemd/issues/27975 + Security relevant changes: * pam_systemd will now by default pass the CAP_WAKE_ALARM ambient