]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
xdg-autostart: ignore all empty entries in multi-string entries 16388/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 7 Jul 2020 09:31:17 +0000 (11:31 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 7 Jul 2020 12:02:16 +0000 (14:02 +0200)
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

src/test/test-xdg-autostart.c
src/xdg-autostart-generator/xdg-autostart-service.c

index cc75bc602426545032cbfc98bb7b5f447cb3d0ec..70287b3c554f7901ea44fcb65e239d74439b5e59 100644 (file)
@@ -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;
index a19d2d7e249f87201d65ffcbaf63d6ec04814798..4a30f9e43354fe5e8016f0edd15534c26bf11beb 100644 (file)
@@ -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;