From: David Herrmann Date: Mon, 30 Jul 2012 05:48:31 +0000 (-0700) Subject: Input: uinput - return -EINVAL when read buffer size is too small X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f40033acc2d14acecd1b27a79dc8a0ad437e619a;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git Input: uinput - return -EINVAL when read buffer size is too small 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 Signed-off-by: Dmitry Torokhov --- diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 1b4ee4a5c49c..e74ed9cc6371 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -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;