Re: [Spice-devel] [PATCH vd_agent_linux v3 2/2] Check errors setting standard file descriptors

2019-01-07 Thread Christophe Fergeau

Acked-by: Christophe Fergeau 

On Fri, Jan 04, 2019 at 10:56:24AM +, Frediano Ziglio wrote:
> Signed-off-by: Frediano Ziglio 
> ---
>  src/vdagent/vdagent.c   | 16 
>  src/vdagentd/vdagentd.c | 16 
>  2 files changed, 24 insertions(+), 8 deletions(-)
> 
> Changes since v2:
> - avoid long if chaining.
> 
> diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
> index 9642a30..90247f9 100644
> --- a/src/vdagent/vdagent.c
> +++ b/src/vdagent/vdagent.c
> @@ -280,7 +280,6 @@ static void wait_and_exit(int s)
>  
>  static int daemonize(void)
>  {
> -int x;
>  int fd[2];
>  
>  if (socketpair(PF_LOCAL, SOCK_STREAM, 0, fd)) {
> @@ -295,9 +294,18 @@ static int daemonize(void)
>  close(STDOUT_FILENO);
>  close(STDERR_FILENO);
>  setsid();
> -x = open("/dev/null", O_RDWR);
> -x = dup(x);
> -x = dup(x);
> +// coverity[leaked_handle] just opening standard file descriptors
> +if (open("/dev/null", O_RDWR) != STDIN_FILENO) {
> +exit(1);
> +}
> +// coverity[leaked_handle] just opening standard file descriptors
> +if (dup(STDIN_FILENO) != STDOUT_FILENO) {
> +exit(1);
> +}
> +// coverity[leaked_handle] just opening standard file descriptors
> +if (dup(STDOUT_FILENO) != STDERR_FILENO) {
> +exit(1);
> +}
>  close(fd[0]);
>  return fd[1];
>  case -1:
> diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
> index 5ed29cc..f5ba3c2 100644
> --- a/src/vdagentd/vdagentd.c
> +++ b/src/vdagentd/vdagentd.c
> @@ -941,7 +941,6 @@ static void agent_read_complete(struct udscs_connection 
> **connp,
>  
>  static void daemonize(void)
>  {
> -int x;
>  FILE *pidfile;
>  
>  /* detach from terminal */
> @@ -951,9 +950,18 @@ static void daemonize(void)
>  close(STDOUT_FILENO);
>  close(STDERR_FILENO);
>  setsid();
> -x = open("/dev/null", O_RDWR);
> -x = dup(x);
> -x = dup(x);
> +// coverity[leaked_handle] just opening standard file descriptors
> +if (open("/dev/null", O_RDWR) != STDIN_FILENO) {
> +exit(1);
> +}
> +// coverity[leaked_handle] just opening standard file descriptors
> +if (dup(STDIN_FILENO) != STDOUT_FILENO) {
> +exit(1);
> +}
> +// coverity[leaked_handle] just opening standard file descriptors
> +if (dup(STDOUT_FILENO) != STDERR_FILENO) {
> +exit(1);
> +}
>  pidfile = fopen(pidfilename, "w");
>  if (pidfile) {
>  fprintf(pidfile, "%d\n", (int)getpid());
> -- 
> 2.20.1
> 
> ___
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel


signature.asc
Description: PGP signature
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH vd_agent_linux v3 2/2] Check errors setting standard file descriptors

2019-01-04 Thread Frediano Ziglio
Signed-off-by: Frediano Ziglio 
---
 src/vdagent/vdagent.c   | 16 
 src/vdagentd/vdagentd.c | 16 
 2 files changed, 24 insertions(+), 8 deletions(-)

Changes since v2:
- avoid long if chaining.

diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
index 9642a30..90247f9 100644
--- a/src/vdagent/vdagent.c
+++ b/src/vdagent/vdagent.c
@@ -280,7 +280,6 @@ static void wait_and_exit(int s)
 
 static int daemonize(void)
 {
-int x;
 int fd[2];
 
 if (socketpair(PF_LOCAL, SOCK_STREAM, 0, fd)) {
@@ -295,9 +294,18 @@ static int daemonize(void)
 close(STDOUT_FILENO);
 close(STDERR_FILENO);
 setsid();
-x = open("/dev/null", O_RDWR);
-x = dup(x);
-x = dup(x);
+// coverity[leaked_handle] just opening standard file descriptors
+if (open("/dev/null", O_RDWR) != STDIN_FILENO) {
+exit(1);
+}
+// coverity[leaked_handle] just opening standard file descriptors
+if (dup(STDIN_FILENO) != STDOUT_FILENO) {
+exit(1);
+}
+// coverity[leaked_handle] just opening standard file descriptors
+if (dup(STDOUT_FILENO) != STDERR_FILENO) {
+exit(1);
+}
 close(fd[0]);
 return fd[1];
 case -1:
diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
index 5ed29cc..f5ba3c2 100644
--- a/src/vdagentd/vdagentd.c
+++ b/src/vdagentd/vdagentd.c
@@ -941,7 +941,6 @@ static void agent_read_complete(struct udscs_connection 
**connp,
 
 static void daemonize(void)
 {
-int x;
 FILE *pidfile;
 
 /* detach from terminal */
@@ -951,9 +950,18 @@ static void daemonize(void)
 close(STDOUT_FILENO);
 close(STDERR_FILENO);
 setsid();
-x = open("/dev/null", O_RDWR);
-x = dup(x);
-x = dup(x);
+// coverity[leaked_handle] just opening standard file descriptors
+if (open("/dev/null", O_RDWR) != STDIN_FILENO) {
+exit(1);
+}
+// coverity[leaked_handle] just opening standard file descriptors
+if (dup(STDIN_FILENO) != STDOUT_FILENO) {
+exit(1);
+}
+// coverity[leaked_handle] just opening standard file descriptors
+if (dup(STDOUT_FILENO) != STDERR_FILENO) {
+exit(1);
+}
 pidfile = fopen(pidfilename, "w");
 if (pidfile) {
 fprintf(pidfile, "%d\n", (int)getpid());
-- 
2.20.1

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel