diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-07-08 14:18:46 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-07-09 01:25:35 +0200 |
commit | 334c0979f37adab7cf6df01cff1ee818bf72d7b2 (patch) | |
tree | 06ecd1390d54449a919b5a0380de7135d595a380 /src/core | |
parent | cd132992bb52b921387289006cb8eb481e7d33a1 (diff) | |
download | systemd-334c0979f37adab7cf6df01cff1ee818bf72d7b2.tar.gz systemd-334c0979f37adab7cf6df01cff1ee818bf72d7b2.tar.bz2 systemd-334c0979f37adab7cf6df01cff1ee818bf72d7b2.zip |
pid1: fix serialization/deserialization of commmands with spaces
Fixes #12258.
This is enough to reproduce:
$ systemd-run bash -c 'sleep 10' && systemctl daemon-reload
would result in
Current command vanished from the unit file.
We would serialize as:
ExecStart 0 /usr/bin/bash /usr/bin/bash -c sleep 10000
which of course can't work.
Now we serialize as
ExecStart 0 /usr/bin/bash "/usr/bin/bash" "-c" "sleep 10".
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/service.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/core/service.c b/src/core/service.c index 4b50d8d029..a7031df48a 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -2530,14 +2530,16 @@ static int service_serialize_exec_command(Unit *u, FILE *f, ExecCommand *command return log_oom(); n = strlen(e); - if (!GREEDY_REALLOC(args, allocated, length + 1 + n + 1)) + if (!GREEDY_REALLOC(args, allocated, length + 2 + n + 2)) return log_oom(); if (length > 0) args[length++] = ' '; + args[length++] = '"'; memcpy(args + length, e, n); length += n; + args[length++] = '"'; } if (!GREEDY_REALLOC(args, allocated, length + 1)) @@ -2682,7 +2684,7 @@ static int service_deserialize_exec_command(Unit *u, const char *key, const char for (;;) { _cleanup_free_ char *arg = NULL; - r = extract_first_word(&value, &arg, NULL, EXTRACT_CUNESCAPE); + r = extract_first_word(&value, &arg, NULL, EXTRACT_CUNESCAPE | EXTRACT_UNQUOTE); if (r < 0) return r; if (r == 0) |