summaryrefslogtreecommitdiffstats
path: root/src/run/run.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-11-24 17:05:41 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-11-25 04:52:35 +0100
commit2c29813da3421b77eca5e5cdc3b9a863cad473b9 (patch)
tree14883324bd6cfedfbad59daaee144b968c40bf2f /src/run/run.c
parentrules: don't condition usb-gadget.target target on 'add' action (diff)
downloadsystemd-2c29813da3421b77eca5e5cdc3b9a863cad473b9.tar.xz
systemd-2c29813da3421b77eca5e5cdc3b9a863cad473b9.zip
run: escape command for description
The command arguments may contain spurious characters, e.g. line-break. When we use command arguments as a description of a unit, we should escape them. Fixes #30187.
Diffstat (limited to '')
-rw-r--r--src/run/run.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/run/run.c b/src/run/run.c
index fdca8fa981..f97150eaab 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -18,6 +18,7 @@
#include "bus-wait-for-jobs.h"
#include "calendarspec.h"
#include "env-util.h"
+#include "escape.h"
#include "exit-status.h"
#include "fd-util.h"
#include "format-util.h"
@@ -1932,17 +1933,19 @@ static int run(int argc, char* argv[]) {
}
if (!arg_description) {
- description = strv_join(arg_cmdline, " ");
- if (!description)
- return log_oom();
+ if (strv_isempty(arg_cmdline))
+ arg_description = arg_unit;
+ else {
+ _cleanup_free_ char *joined = strv_join(arg_cmdline, " ");
+ if (!joined)
+ return log_oom();
- if (arg_unit && isempty(description)) {
- r = free_and_strdup(&description, arg_unit);
- if (r < 0)
+ description = shell_escape(joined, "\"");
+ if (!description)
return log_oom();
- }
- arg_description = description;
+ arg_description = description;
+ }
}
/* For backward compatibility reasons env var expansion is disabled by default for scopes, and