path: limit path device nodes to PATH_MAX characters
authorPeter Hutterer <peter.hutterer@who-t.net>
Fri, 8 Feb 2019 01:08:36 +0000 (11:08 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 11 Feb 2019 03:35:53 +0000 (03:35 +0000)
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/path-seat.c
test/test-path.c

index aa68780476d5c95b8e4bea20fde7d4e8abc477b7..78f42da792e3fa99a5a4a33f677549ee301100dc 100644 (file)
@@ -331,6 +331,13 @@ libinput_path_add_device(struct libinput *libinput,
        struct udev_device *udev_device;
        struct libinput_device *device;
 
+       if (strlen(path) > PATH_MAX) {
+               log_bug_client(libinput,
+                              "Unexpected path, limited to %d characters.\n",
+                              PATH_MAX);
+               return NULL;
+       }
+
        if (libinput->interface_backend != &interface_backend) {
                log_bug_client(libinput, "Mismatching backends.\n");
                return NULL;
index f7c4de6fce0aec83992ccbe2e3d38d22a863df58..812e26153b1a1c78422b8d1a594c430f2582ddad 100644 (file)
@@ -190,6 +190,38 @@ START_TEST(path_create_invalid_file)
 }
 END_TEST
 
+START_TEST(path_create_pathmax_file)
+{
+       struct libinput *li;
+       struct libinput_device *device;
+       char *path;
+       struct counter counter;
+
+       path = zalloc(PATH_MAX * 2);
+       memset(path, 'a', PATH_MAX * 2 - 1);
+
+       counter.open_func_count = 0;
+       counter.close_func_count = 0;
+
+       li = libinput_path_create_context(&counting_interface, &counter);
+
+       litest_set_log_handler_bug(li);
+       ck_assert(li != NULL);
+       device = libinput_path_add_device(li, path);
+       ck_assert(device == NULL);
+
+       ck_assert_int_eq(counter.open_func_count, 0);
+       ck_assert_int_eq(counter.close_func_count, 0);
+
+       litest_restore_log_handler(li);
+       libinput_unref(li);
+       ck_assert_int_eq(counter.close_func_count, 0);
+
+       free(path);
+}
+END_TEST
+
+
 START_TEST(path_create_destroy)
 {
        struct libinput *li;
@@ -987,6 +1019,7 @@ TEST_COLLECTION(path)
        litest_add_no_device("path:create", path_create_invalid);
        litest_add_no_device("path:create", path_create_invalid_file);
        litest_add_no_device("path:create", path_create_invalid_kerneldev);
+       litest_add_no_device("path:create", path_create_pathmax_file);
        litest_add_no_device("path:create", path_create_destroy);
        litest_add("path:create", path_force_destroy, LITEST_ANY, LITEST_ANY);
        litest_add_no_device("path:create", path_set_user_data);