Skip to content

Commit

Permalink
Input: uinput - return -EINVAL when read buffer size is too small
Browse files Browse the repository at this point in the history
Let's check whether the user-supplied buffer is actually big enough and
return -EINVAL if it is not. This differs from current behavior, which
caused 0 to be returned and actually does not make any sense, as
broken application will simply repeat the read getting into endless
loop.

Note that we treat 0 as a special case, according to the standard:

"Before any action described below is taken, and if nbyte is zero,
the read() function may detect and return errors as described below.
In the absence of errors, or if error detection is not performed,
the read() function shall return zero and have no other results."

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
  • Loading branch information
David Herrmann authored and dtor committed Aug 22, 2012
1 parent 929d1af commit f40033a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/input/misc/uinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@ static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count,
struct input_event event;
int retval = 0;

if (count != 0 && count < input_event_size())
return -EINVAL;

if (udev->state != UIST_CREATED)
return -ENODEV;

Expand Down

0 comments on commit f40033a

Please sign in to comment.