From: Zbigniew Jędrzejewski-Szmek Date: Tue, 7 Jul 2020 09:31:17 +0000 (+0200) Subject: xdg-autostart: ignore all empty entries in multi-string entries X-Git-Tag: v246-rc1~16^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16388%2Fhead;p=thirdparty%2Fsystemd.git xdg-autostart: ignore all empty entries in multi-string entries The desktop file specification allows entries like ";;;;;;", full of empty strings. But looking at the actual list of supported keys [1], empty entries are meaningless (unless we would allow e.g. the desktop name to be the empty string. But that doesn't seem very useful either). So let's just simplify our life and skip any empty substrings entirely. This would also resolve the fuzzer case: $ valgrind build/fuzz-xdg-desktop test/fuzz/fuzz-xdg-desktop/oss-fuzz-22812 test/fuzz/fuzz-xdg-desktop/oss-fuzz-22812... ok ==2899241== HEAP SUMMARY: ==2899241== in use at exit: 0 bytes in 0 blocks ==2899241== total heap usage: 484,385 allocs, 484,385 frees, 12,411,330 bytes allocated ↓ ==2899650== HEAP SUMMARY: ==2899650== in use at exit: 0 bytes in 0 blocks ==2899650== total heap usage: 1,325 allocs, 1,325 frees, 1,463,602 bytes allocated --- diff --git a/src/test/test-xdg-autostart.c b/src/test/test-xdg-autostart.c index cc75bc60242..70287b3c554 100644 --- a/src/test/test-xdg-autostart.c +++ b/src/test/test-xdg-autostart.c @@ -67,7 +67,7 @@ static void test_xdg_desktop_parse(unsigned i, const char *s) { case 0: assert_se(streq(service->exec_string, "/bin/sleep 100")); assert_se(strv_equal(service->only_show_in, STRV_MAKE("A", "B"))); - assert_se(strv_equal(service->not_show_in, STRV_MAKE("C", "", "D\\;", "E"))); + assert_se(strv_equal(service->not_show_in, STRV_MAKE("C", "D\\;", "E"))); assert_se(!service->hidden); break; case 1: @@ -81,14 +81,12 @@ static void test_xdg_desktop_parse(unsigned i, const char *s) { } int main(int argc, char *argv[]) { - size_t i; - test_setup_logging(LOG_DEBUG); test_translate_name(); test_xdg_format_exec_start(); - for (i = 0; i < ELEMENTSOF(xdg_desktop_file); i++) + for (size_t i = 0; i < ELEMENTSOF(xdg_desktop_file); i++) test_xdg_desktop_parse(i, xdg_desktop_file[i]); return 0; diff --git a/src/xdg-autostart-generator/xdg-autostart-service.c b/src/xdg-autostart-generator/xdg-autostart-service.c index a19d2d7e249..4a30f9e4335 100644 --- a/src/xdg-autostart-generator/xdg-autostart-service.c +++ b/src/xdg-autostart-generator/xdg-autostart-service.c @@ -192,6 +192,9 @@ static int strv_strndup_unescape_and_push( const char *start, const char *end) { + if (end == start) + return 0; + _cleanup_free_ char *copy = NULL; int r; @@ -270,14 +273,12 @@ static int xdg_config_parse_strv( } } - /* Any trailing entry should be ignored if it is empty. */ - if (end > start) { - r = strv_strndup_unescape_and_push(unit, filename, line, - &sv, &n_allocated, &n, - start, end); - if (r < 0) - return r; - } + /* Handle the trailing entry after the last separator */ + r = strv_strndup_unescape_and_push(unit, filename, line, + &sv, &n_allocated, &n, + start, end); + if (r < 0) + return r; *ret_sv = TAKE_PTR(sv); return 0;