ACK: [PATCH] hotkey: check lstat() return value rather

Alex Hung alex.hung at canonical.com
Fri May 10 01:13:48 UTC 2013


On 05/07/2013 08:44 AM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Coverity CID #997313, Unchecked return value from library
>
> Check return from lstat rather than blindly accepting that
> it always works.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>   src/hotkey/hotkey/hotkey.c | 23 ++++++++++++-----------
>   1 file changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/src/hotkey/hotkey/hotkey.c b/src/hotkey/hotkey/hotkey.c
> index ff3c669..381f029 100644
> --- a/src/hotkey/hotkey/hotkey.c
> +++ b/src/hotkey/hotkey/hotkey.c
> @@ -154,19 +154,20 @@ static char *hotkey_find_keyboard(char *path)
>   		if (strlen(entry->d_name) > 3) {
>   			snprintf(filename, sizeof(filename), "%s/%s",
>   				path, entry->d_name);
> -			lstat(filename, &statbuf);
> -			if (S_ISDIR(statbuf.st_mode)) {
> -				if (!S_ISLNK(statbuf.st_mode))
> -					if ((dev = hotkey_find_keyboard(filename)) != NULL)
> -						break;
> -			} else {
> -				if ((data = fwts_get(filename)) != NULL) {
> -					if (strncmp(data, AT_KEYBOARD, sizeof(AT_KEYBOARD)-1) == 0) {
> -						dev = hotkey_device(path);
> +			if (lstat(filename, &statbuf) == 0) {
> +				if (S_ISDIR(statbuf.st_mode)) {
> +					if (!S_ISLNK(statbuf.st_mode))
> +						if ((dev = hotkey_find_keyboard(filename)) != NULL)
> +							break;
> +				} else {
> +					if ((data = fwts_get(filename)) != NULL) {
> +						if (strncmp(data, AT_KEYBOARD, sizeof(AT_KEYBOARD)-1) == 0) {
> +							dev = hotkey_device(path);
> +							free(data);
> +							break;
> +						}
>   						free(data);
> -						break;
>   					}
> -					free(data);
>   				}
>   			}
>   		}
>
Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list