Patchwork lib: fwts_acpid: check fcntl return rather than assuming it works

login
register
mail settings
Submitter Colin King
Date May 7, 2013, 12:40 a.m.
Message ID <1367887207-24750-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/241861/
State Accepted
Headers show

Comments

Colin King - May 7, 2013, 12:40 a.m.
From: Colin Ian King <colin.king@canonical.com>

Coverity CID #997312, Unchecked return value from library

We should check fcntl() works rather than blindly assuming it worked
OK. Return error value if it fails.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_acpid.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Alex Hung - May 10, 2013, 1:11 a.m.
On 05/07/2013 08:40 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997312, Unchecked return value from library
>
> We should check fcntl() works rather than blindly assuming it worked
> OK. Return error value if it fails.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_acpid.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_acpid.c b/src/lib/src/fwts_acpid.c
> index 5dc1d59..494be53 100644
> --- a/src/lib/src/fwts_acpid.c
> +++ b/src/lib/src/fwts_acpid.c
> @@ -60,7 +60,10 @@ int fwts_acpi_event_open(void)
>                   return ret;
>   	}
>
> -	fcntl(fd, F_SETFD, FD_CLOEXEC);
> +	if ((ret = fcntl(fd, F_SETFD, FD_CLOEXEC)) < 0) {
> +		close(fd);
> +		return ret;
> +	}
>
>           return fd;
>   }
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin - May 20, 2013, 7:18 a.m.
On Tue, May 7, 2013 at 8:40 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997312, Unchecked return value from library
>
> We should check fcntl() works rather than blindly assuming it worked
> OK. Return error value if it fails.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_acpid.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_acpid.c b/src/lib/src/fwts_acpid.c
> index 5dc1d59..494be53 100644
> --- a/src/lib/src/fwts_acpid.c
> +++ b/src/lib/src/fwts_acpid.c
> @@ -60,7 +60,10 @@ int fwts_acpi_event_open(void)
>                  return ret;
>         }
>
> -       fcntl(fd, F_SETFD, FD_CLOEXEC);
> +       if ((ret = fcntl(fd, F_SETFD, FD_CLOEXEC)) < 0) {
> +               close(fd);
> +               return ret;
> +       }
>
>          return fd;
>  }
> --
> 1.8.1.2
>

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

Patch

diff --git a/src/lib/src/fwts_acpid.c b/src/lib/src/fwts_acpid.c
index 5dc1d59..494be53 100644
--- a/src/lib/src/fwts_acpid.c
+++ b/src/lib/src/fwts_acpid.c
@@ -60,7 +60,10 @@  int fwts_acpi_event_open(void)
                 return ret;
 	}
 
-	fcntl(fd, F_SETFD, FD_CLOEXEC);
+	if ((ret = fcntl(fd, F_SETFD, FD_CLOEXEC)) < 0) {
+		close(fd);
+		return ret;
+	}
 
         return fd;
 }