[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv2 3/4] command: check for fork error before closing fd



From: Wen Congyang <wency cn fujitsu com>

We should not set *outfd or *errfd if virExecWithHook() failed
because the caller may close these fds.

Bug present since v0.4.5 (commit 60ed1d2a).
---

v2: split into separate patch, track down origin

 src/util/command.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/util/command.c b/src/util/command.c
index 1a22508..ba43078 100644
--- a/src/util/command.c
+++ b/src/util/command.c
@@ -492,6 +492,10 @@ virExecWithHook(const char *const*argv,
     }

     if (pid) { /* parent */
+        if (forkRet < 0) {
+            goto cleanup;
+        }
+
         VIR_FORCE_CLOSE(null);
         if (outfd && *outfd == -1) {
             VIR_FORCE_CLOSE(pipeout[1]);
@@ -502,10 +506,6 @@ virExecWithHook(const char *const*argv,
             *errfd = pipeerr[0];
         }

-        if (forkRet < 0) {
-            goto cleanup;
-        }
-
         *retpid = pid;

         if (binary != argv[0])
-- 
1.7.7.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]