From 2c29813da3421b77eca5e5cdc3b9a863cad473b9 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 25 Nov 2023 01:05:41 +0900 Subject: [PATCH] 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. --- src/run/run.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/run/run.c b/src/run/run.c index fdca8fa..f97150e 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 -- 2.7.4