mirror of
https://github.com/systemd/systemd.git
synced 2026-08-04 15:10:33 +00:00
util-lib: follow shell syntax for escape in quotes
Fixes #10659. This changes the behaviour of parsing environment files to more closely follow POSIX shell standards. This has the effect that these variables defined in a file: VAR1='\value' VAR2="\value" Are now interpreted as `\value` instead of interpreting the `\` character and interpreting them as `value`. For more information about the behaviour followed, see: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02
This commit is contained in:
@@ -35,7 +35,6 @@ static int parse_env_file_internal(
|
||||
VALUE,
|
||||
VALUE_ESCAPE,
|
||||
SINGLE_QUOTE_VALUE,
|
||||
SINGLE_QUOTE_VALUE_ESCAPE,
|
||||
DOUBLE_QUOTE_VALUE,
|
||||
DOUBLE_QUOTE_VALUE_ESCAPE,
|
||||
COMMENT,
|
||||
@@ -186,8 +185,6 @@ static int parse_env_file_internal(
|
||||
case SINGLE_QUOTE_VALUE:
|
||||
if (c == '\'')
|
||||
state = PRE_VALUE;
|
||||
else if (c == '\\')
|
||||
state = SINGLE_QUOTE_VALUE_ESCAPE;
|
||||
else {
|
||||
if (!GREEDY_REALLOC(value, value_alloc, n_value+2))
|
||||
return -ENOMEM;
|
||||
@@ -197,17 +194,6 @@ static int parse_env_file_internal(
|
||||
|
||||
break;
|
||||
|
||||
case SINGLE_QUOTE_VALUE_ESCAPE:
|
||||
state = SINGLE_QUOTE_VALUE;
|
||||
|
||||
if (!strchr(NEWLINE, c)) {
|
||||
if (!GREEDY_REALLOC(value, value_alloc, n_value+2))
|
||||
return -ENOMEM;
|
||||
|
||||
value[n_value++] = c;
|
||||
}
|
||||
break;
|
||||
|
||||
case DOUBLE_QUOTE_VALUE:
|
||||
if (c == '\"')
|
||||
state = PRE_VALUE;
|
||||
@@ -225,12 +211,17 @@ static int parse_env_file_internal(
|
||||
case DOUBLE_QUOTE_VALUE_ESCAPE:
|
||||
state = DOUBLE_QUOTE_VALUE;
|
||||
|
||||
if (!strchr(NEWLINE, c)) {
|
||||
if (c == '"') {
|
||||
if (!GREEDY_REALLOC(value, value_alloc, n_value+2))
|
||||
return -ENOMEM;
|
||||
|
||||
value[n_value++] = '"';
|
||||
} else if (!strchr(NEWLINE, c)) {
|
||||
if (!GREEDY_REALLOC(value, value_alloc, n_value+3))
|
||||
return -ENOMEM;
|
||||
value[n_value++] = '\\';
|
||||
value[n_value++] = c;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case COMMENT:
|
||||
@@ -253,7 +244,6 @@ static int parse_env_file_internal(
|
||||
VALUE,
|
||||
VALUE_ESCAPE,
|
||||
SINGLE_QUOTE_VALUE,
|
||||
SINGLE_QUOTE_VALUE_ESCAPE,
|
||||
DOUBLE_QUOTE_VALUE,
|
||||
DOUBLE_QUOTE_VALUE_ESCAPE)) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user