mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-24 19:20:06 +01:00
uinput: fix race condition in uinput syspath check
In theory, the device could change between stat() call and open(), resulting in us opening the new device. Change to open() first, then fstat() on the fd. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
This commit is contained in:
parent
3c85fcb62f
commit
006f10cfcb
1 changed files with 8 additions and 8 deletions
|
|
@ -225,19 +225,19 @@ fetch_syspath_and_devnode(struct libevdev_uinput *uinput_dev)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (stat(buf, &st) == -1)
|
||||
continue;
|
||||
|
||||
/* created before UI_DEV_CREATE, or after it finished */
|
||||
if (st.st_ctime < uinput_dev->ctime[0] ||
|
||||
st.st_ctime > uinput_dev->ctime[1])
|
||||
continue;
|
||||
|
||||
/* created within time frame */
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd < 0)
|
||||
continue;
|
||||
|
||||
/* created before UI_DEV_CREATE, or after it finished */
|
||||
if (fstat(fd, &st) == -1 ||
|
||||
st.st_ctime < uinput_dev->ctime[0] ||
|
||||
st.st_ctime > uinput_dev->ctime[1]) {
|
||||
close(fd);
|
||||
continue;
|
||||
}
|
||||
|
||||
len = read(fd, buf, sizeof(buf));
|
||||
close(fd);
|
||||
if (len <= 0)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue