]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
command: check for fork error before closing fd
authorWen Congyang <wency@cn.fujitsu.com>
Wed, 30 May 2012 09:20:44 +0000 (17:20 +0800)
committerCole Robinson <crobinso@redhat.com>
Fri, 15 Jun 2012 14:58:27 +0000 (10:58 -0400)
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).
(cherry picked from commit 746ff701e8727439cac8ca72531d82e5cb7fa129)

src/util/command.c

index d62d9d1a15cc11af0cbbd25aecdba1dafdb45329..5394a02f73a6a964d2eb4f69d86c91a482a66fb9 100644 (file)
@@ -394,6 +394,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]);
@@ -404,10 +408,6 @@ virExecWithHook(const char *const*argv,
             *errfd = pipeerr[0];
         }
 
-        if (forkRet < 0) {
-            goto cleanup;
-        }
-
         *retpid = pid;
 
         if (binary != argv[0])