Skip to content

Commit

Permalink
udev: restrict the seat ID to 256 characters
Browse files Browse the repository at this point in the history
Anything longer than that is likely a bug.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Feb 11, 2019
1 parent 3a89f95 commit 4353ed9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/udev-seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,22 @@ libinput_udev_assign_seat(struct libinput *libinput,
{
struct udev_input *input = (struct udev_input*)libinput;

if (!seat_id)
return -1;

if (strlen(seat_id) > 256) {
log_bug_client(libinput,
"Unexpected seat id, limited to 256 characters.\n");
return -1;
}

/* We cannot do this during udev_create_context because the log
* handler isn't set up there but we really want to log to the right
* place if the quirks run into parser errors. So we have to do it
* here since we can expect the log handler to be set up by now.
*/
libinput_init_quirks(libinput);

if (!seat_id)
return -1;

if (libinput->interface_backend != &interface_backend) {
log_bug_client(libinput, "Mismatching backends.\n");
return -1;
Expand Down
25 changes: 25 additions & 0 deletions test/test-udev.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,30 @@ START_TEST(udev_create_empty_seat)
}
END_TEST

START_TEST(udev_create_seat_too_long)
{
struct libinput *li;
struct udev *udev;
char seatname[258];

memset(seatname, 'a', sizeof(seatname) - 1);
seatname[sizeof(seatname) - 1] = '\0';

udev = udev_new();
ck_assert(udev != NULL);

li = libinput_udev_create_context(&simple_interface, NULL, udev);
litest_set_log_handler_bug(li);

ck_assert_int_eq(libinput_udev_assign_seat(li, seatname), -1);

litest_assert_empty_queue(li);

libinput_unref(li);
udev_unref(udev);
}
END_TEST

START_TEST(udev_set_user_data)
{
struct libinput *li;
Expand Down Expand Up @@ -651,6 +675,7 @@ TEST_COLLECTION(udev)
litest_add_no_device("udev:create", udev_create_NULL);
litest_add_no_device("udev:create", udev_create_seat0);
litest_add_no_device("udev:create", udev_create_empty_seat);
litest_add_no_device("udev:create", udev_create_seat_too_long);
litest_add_no_device("udev:create", udev_set_user_data);

litest_add_no_device("udev:seat", udev_added_seat_default);
Expand Down

0 comments on commit 4353ed9

Please sign in to comment.