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

Keng-Yu Lin kengyu at canonical.com
Mon May 20 07:19:54 UTC 2013


On Tue, May 7, 2013 at 8:44 AM, Colin King <colin.king at canonical.com> 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);
>                                 }
>                         }
>                 }
> --
> 1.8.1.2
>

Acked-by: Keng-Yu Lin <kengyu at canonical.com>



More information about the fwts-devel mailing list