diff options
author | Benjamin Berg <bberg@redhat.com> | 2022-03-24 13:00:59 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-03-25 06:50:41 +0100 |
commit | c2b42ec413aefe05681c20f294662cab11d89320 (patch) | |
tree | 41ad542756d03d4d543991d47eea6d2fe38838db /src/xdg-autostart-generator | |
parent | efi-loader: drop harmful assertion (diff) | |
download | systemd-c2b42ec413aefe05681c20f294662cab11d89320.tar.xz systemd-c2b42ec413aefe05681c20f294662cab11d89320.zip |
xdg-autostart-service: Fix binary escaping and simplify code a bit
Instead of escaping each component separately, we can instead use
quote_command_line. Doing so simplifies the code and fixes an issue
where spaces inside the executable name were not escaped.
Co-Authored-By: David Edmundson <kde@davidedmundson.co.uk>
Diffstat (limited to 'src/xdg-autostart-generator')
-rw-r--r-- | src/xdg-autostart-generator/test-xdg-autostart.c | 4 | ||||
-rw-r--r-- | src/xdg-autostart-generator/xdg-autostart-service.c | 23 |
2 files changed, 8 insertions, 19 deletions
diff --git a/src/xdg-autostart-generator/test-xdg-autostart.c b/src/xdg-autostart-generator/test-xdg-autostart.c index 841a5606f6..a357cf50fe 100644 --- a/src/xdg-autostart-generator/test-xdg-autostart.c +++ b/src/xdg-autostart-generator/test-xdg-autostart.c @@ -25,13 +25,13 @@ static void test_xdg_format_exec_start_one(const char *exec, const char *expecte } TEST(xdg_format_exec_start) { - test_xdg_format_exec_start_one("/bin/sleep 100", "/bin/sleep \"100\""); + test_xdg_format_exec_start_one("/bin/sleep 100", "/bin/sleep 100"); /* All standardised % identifiers are stripped. */ test_xdg_format_exec_start_one("/bin/sleep %f \"%F\" %u %U %d %D\t%n %N %i %c %k %v %m", "/bin/sleep"); /* Unknown % identifier currently remain, but are escaped. */ - test_xdg_format_exec_start_one("/bin/sleep %X \"%Y\"", "/bin/sleep \"%%X\" \"%%Y\""); + test_xdg_format_exec_start_one("/bin/sleep %X \"%Y\"", "/bin/sleep %%X %%Y"); test_xdg_format_exec_start_one("/bin/sleep \";\\\"\"", "/bin/sleep \";\\\"\""); } diff --git a/src/xdg-autostart-generator/xdg-autostart-service.c b/src/xdg-autostart-generator/xdg-autostart-service.c index 0e1e84eda8..9c4a7f2404 100644 --- a/src/xdg-autostart-generator/xdg-autostart-service.c +++ b/src/xdg-autostart-generator/xdg-autostart-service.c @@ -396,7 +396,7 @@ int xdg_autostart_format_exec_start( first_arg = true; for (i = n = 0; exec_split[i]; i++) { - _cleanup_free_ char *c = NULL, *raw = NULL, *p = NULL, *escaped = NULL, *quoted = NULL; + _cleanup_free_ char *c = NULL, *raw = NULL, *percent = NULL; ssize_t l; l = cunescape(exec_split[i], 0, &c); @@ -412,11 +412,7 @@ int xdg_autostart_format_exec_start( if (r < 0) return log_info_errno(r, "Exec binary '%s' does not exist: %m", c); - escaped = cescape(executable); - if (!escaped) - return log_oom(); - - free_and_replace(exec_split[n++], escaped); + free_and_replace(exec_split[n++], executable); continue; } @@ -445,23 +441,16 @@ int xdg_autostart_format_exec_start( raw = strreplace(c, "%%", "%"); if (!raw) return log_oom(); - p = strreplace(raw, "%", "%%"); - if (!p) - return log_oom(); - escaped = cescape(p); - if (!escaped) - return log_oom(); - - quoted = strjoin("\"", escaped, "\""); - if (!quoted) + percent = strreplace(raw, "%", "%%"); + if (!percent) return log_oom(); - free_and_replace(exec_split[n++], quoted); + free_and_replace(exec_split[n++], percent); } for (; exec_split[n]; n++) exec_split[n] = mfree(exec_split[n]); - res = strv_join(exec_split, " "); + res = quote_command_line(exec_split, SHELL_ESCAPE_EMPTY); if (!res) return log_oom(); |