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

John Ferlan jferlan at redhat.com
Tue Jul 23 13:58:11 UTC 2019


If the dup2 fails, then we aren't going to get the correct result.

Found by Coverity

Signed-off-by: John Ferlan <jferlan at 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




More information about the libvir-list mailing list