]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/shared/bus-unit-util.c
Use "dollar-single-quotes" to escape shell-sensitive strings 6113/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 11 Jun 2017 19:24:07 +0000 (15:24 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 19 Jun 2017 23:39:43 +0000 (19:39 -0400)
commit804ee07c1370d49aa9a555c91c26fe3ed22f9957
treee313b1c284d4efe675d2ff08d3ece19ccc963a8e
parent42d3bf86bb75842602d3712caa2baccd09a1c795
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.
man/systemctl.xml
src/basic/escape.c
src/basic/escape.h
src/core/job.c
src/environment-d-generator/environment-d-generator.c
src/shared/bus-unit-util.c
src/systemctl/systemctl.c
src/test/test-escape.c