diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-06-11 15:24:07 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-06-19 19:39:43 -0400 |
commit | 804ee07c1370d49aa9a555c91c26fe3ed22f9957 (patch) | |
tree | e313b1c284d4efe675d2ff08d3ece19ccc963a8e /src/environment-d-generator | |
parent | 42d3bf86bb75842602d3712caa2baccd09a1c795 (diff) | |
download | systemd-804ee07c1370d49aa9a555c91c26fe3ed22f9957.tar.gz |
Use "dollar-single-quotes" to escape shell-sensitive strings
Also called "ANSI-C Quoting" in info:(bash) ANSI-C Quoting.
The escaping rules are a POSIX proposal, and are described in
http://austingroupbugs.net/view.php?id=249. There's a lot of back-and-forth on
the details of escaping of control characters, but we'll be only using a small
subset of the syntax that is common to all proposals and is widely supported.
Unfortunately dash and fish and maybe some other shells do not support it (see
the man page patch for a list).
This allows environment variables to be safely exported using show-environment
and imported into the shell. Shells which do not support this syntax will have
to do something like
export $(systemctl show-environment|grep -v '=\$')
or whatever is appropriate in their case. I think csh and fish do not support
the A=B syntax anyway, so the change is moot for them.
Fixes #5536.
v2:
- also escape newlines (which currently disallowed in shell values, so this
doesn't really matter), and tabs (as $'\t'), and ! (as $'!'). This way quoted
output can be included directly in both interactive and noninteractive bash.
Diffstat (limited to 'src/environment-d-generator')
-rw-r--r-- | src/environment-d-generator/environment-d-generator.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/environment-d-generator/environment-d-generator.c b/src/environment-d-generator/environment-d-generator.c index 2d4c4235e4..9c72502373 100644 --- a/src/environment-d-generator/environment-d-generator.c +++ b/src/environment-d-generator/environment-d-generator.c @@ -78,7 +78,7 @@ static int load_and_print(void) { t = strchr(*i, '='); assert(t); - q = shell_maybe_quote(t + 1); + q = shell_maybe_quote(t + 1, ESCAPE_BACKSLASH); if (!q) return log_oom(); |