summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-09-11 15:14:03 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-09-20 12:00:48 +0200
commit4d1922d8bb42540b20ede62958d8b4d426f86b5d (patch)
tree8c2a6b409417f217b9d5fa686a542e9b202be4f7
parent281581cd7437dac5a3f787b7ea73b0bab53bd1e6 (diff)
downloadsystemd-4d1922d8bb42540b20ede62958d8b4d426f86b5d.tar.gz
env-file: bring our decoding of double-quoted strings in env files in line with shell
In shell, inside of double quotes only a select few chars should be escaped. If other chars are escaped this has no effect. Correct the list of chars that need such escaping. Also, make sure we can read back the stuff we wrote out without loss. Fixes: #16788 (cherry picked from commit de008e537dc6e3504f988fa9bd358f783016df8a)
-rw-r--r--src/basic/env-file.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/basic/env-file.c b/src/basic/env-file.c
index 26470796eb..dc92b13a6f 100644
--- a/src/basic/env-file.c
+++ b/src/basic/env-file.c
@@ -209,17 +209,21 @@ static int parse_env_file_internal(
case DOUBLE_QUOTE_VALUE_ESCAPE:
state = DOUBLE_QUOTE_VALUE;
- if (c == '"') {
+ if (strchr(SHELL_NEED_ESCAPE, c)) {
+ /* If this is a char that needs escaping, just unescape it. */
if (!GREEDY_REALLOC(value, value_alloc, n_value+2))
return -ENOMEM;
- value[n_value++] = '"';
- } else if (!strchr(NEWLINE, c)) {
+ value[n_value++] = c;
+ } else if (c != '\n') {
+ /* If other char than what needs escaping, keep the "\" in place, like the
+ * real shell does. */
if (!GREEDY_REALLOC(value, value_alloc, n_value+3))
return -ENOMEM;
value[n_value++] = '\\';
value[n_value++] = c;
}
+ /* Escaped newlines (aka "continuation lines") are eaten up entirely */
break;
case COMMENT: