[libvirt] [PATCH 4/4] tests: Avoid possible error in testExecRestart

John Ferlan posted 4 patches 5 years, 4 months ago
[libvirt] [PATCH 4/4] tests: Avoid possible error in testExecRestart
Posted by John Ferlan 5 years, 4 months ago
If the dup2 fails, then we aren't going to get the correct result.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 tests/virnetdaemontest.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c
index eae630a8f1..d0e9f241e3 100644
--- a/tests/virnetdaemontest.c
+++ b/tests/virnetdaemontest.c
@@ -287,10 +287,11 @@ static int testExecRestart(const void *opaque)
      * fds 100->103 for something else, which is probably
      * fairly reasonable in general
      */
-    dup2(fdserver[0], 100);
-    dup2(fdserver[1], 101);
-    dup2(fdclient[0], 102);
-    dup2(fdclient[1], 103);
+    if (dup2(fdserver[0], 100) < 0 ||
+        dup2(fdserver[1], 101) < 0 ||
+        dup2(fdclient[0], 102) < 0 ||
+        dup2(fdclient[1], 103) < 0)
+        goto cleanup;
 
     if (virAsprintf(&infile, "%s/virnetdaemondata/input-data-%s.json",
                     abs_srcdir, data->jsonfile) < 0)
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 4/4] tests: Avoid possible error in testExecRestart
Posted by Peter Krempa 5 years, 4 months ago
On Tue, Jul 23, 2019 at 09:58:11 -0400, John Ferlan wrote:
> If the dup2 fails, then we aren't going to get the correct result.
> 
> Found by Coverity
> 
> Signed-off-by: John Ferlan <jferlan@redhat.com>
> ---
>  tests/virnetdaemontest.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c
> index eae630a8f1..d0e9f241e3 100644
> --- a/tests/virnetdaemontest.c
> +++ b/tests/virnetdaemontest.c
> @@ -287,10 +287,11 @@ static int testExecRestart(const void *opaque)
>       * fds 100->103 for something else, which is probably
>       * fairly reasonable in general
>       */
> -    dup2(fdserver[0], 100);
> -    dup2(fdserver[1], 101);
> -    dup2(fdclient[0], 102);
> -    dup2(fdclient[1], 103);
> +    if (dup2(fdserver[0], 100) < 0 ||
> +        dup2(fdserver[1], 101) < 0 ||
> +        dup2(fdclient[0], 102) < 0 ||
> +        dup2(fdclient[1], 103) < 0)
> +        goto cleanup;

This will not print any debug message if we hit this.

>  
>      if (virAsprintf(&infile, "%s/virnetdaemondata/input-data-%s.json",
>                      abs_srcdir, data->jsonfile) < 0)
> -- 
> 2.20.1
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list