ACK: [PATCH] hotkey: only process reads of hotkey events that are at least the correct length

Alex Hung alex.hung at canonical.com
Thu May 21 22:52:31 UTC 2015


On 05/14/2015 04:33 AM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
> 
> Coverity Scan found an issue where the comparison to the event structure was
> incorrect when reads were too short in size.
> 
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>  src/hotkey/hotkey/hotkey.c | 22 +++++++++++-----------
>  1 file changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/src/hotkey/hotkey/hotkey.c b/src/hotkey/hotkey/hotkey.c
> index 6e40df1..28d3ef1 100644
> --- a/src/hotkey/hotkey/hotkey.c
> +++ b/src/hotkey/hotkey/hotkey.c
> @@ -90,20 +90,20 @@ static int hotkey_test(fwts_framework *fw, char *dev, fwts_list *hotkeys)
>  	}
>  
>  	while (do_test) {
> -		switch (read(fd, &ev, sizeof(ev))) {
> -		case -1:
> -		case 0:
> +		ssize_t ret = read(fd, &ev, sizeof(ev));
> +
> +		if (ret < (ssize_t)sizeof(ev)) {
>  			do_test = 0;
>  			break;
> -		default:
> -			if ((ev.type == EV_KEY) &&
> -		 	    (ev.code == KEY_ESC) &&
> -			    (ev.value == 0))
> -				do_test = 0;
> -			else
> -				hotkey_check_key(fw, &ev, hotkeys);
> -			break;
>  		}
> +
> +		if ((ev.type == EV_KEY) &&
> +		    (ev.code == KEY_ESC) &&
> +		    (ev.value == 0))
> +			do_test = 0;
> +		else
> +			hotkey_check_key(fw, &ev, hotkeys);
> +		break;
>  	}
>  
>  	if (ioctl(fd, EVIOCGRAB, (void*)0)) {	/* Release */
> 

Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list