]> sourceware.org Git - newlib-cygwin.git/commitdiff
* spawn.cc (child_info_spawn::worker): Save and restore my_wr_proc_pipe around
authorChristopher Faylor <me@cgf.cx>
Sat, 9 Mar 2013 00:11:31 +0000 (00:11 +0000)
committerChristopher Faylor <me@cgf.cx>
Sat, 9 Mar 2013 00:11:31 +0000 (00:11 +0000)
non-execing operations to avoid handle leak seen in
http://cygwin.com/ml/cygwin/2013-03/msg00152.html .

winsup/cygwin/ChangeLog
winsup/cygwin/spawn.cc

index d509568e12e94b913e07f1112d42ac23c40c7fd9..17746b3d2117b63cd8ef68a352167e1acae1495f 100644 (file)
@@ -1,3 +1,9 @@
+2013-03-08  Christopher Faylor  <me.cygwin2013@cgf.cx>
+
+       * spawn.cc (child_info_spawn::worker): Save and restore my_wr_proc_pipe
+       around non-execing operations to avoid handle leak seen in
+       http://cygwin.com/ml/cygwin/2013-03/msg00152.html .
+
 2013-03-07  Corinna Vinschen  <corinna@vinschen.de>
 
        * include/sys/un.h (UNIX_PATH_MAX): Rename from UNIX_PATH_LEN to
index 170f37a8d1d0fece35a94636fdfe3adbc3f747fc..e5152c0e76859b0978ce53f252e03cb38c1c68ce 100644 (file)
@@ -620,6 +620,9 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
       SetHandleInformation (wr_proc_pipe, HANDLE_FLAG_INHERIT, 0);
       SetHandleInformation (parent, HANDLE_FLAG_INHERIT, 0);
     }
+  /* FIXME: racy */
+  if (mode != _P_OVERLAY)
+    SetHandleInformation (my_wr_proc_pipe, HANDLE_FLAG_INHERIT, 0);
   parent_winpid = GetCurrentProcessId ();
 
   /* When ruid != euid we create the new process under the current original
@@ -724,10 +727,9 @@ loop:
        }
     }
 
-  /* Restore impersonation. In case of _P_OVERLAY this isn't
-     allowed since it would overwrite child data. */
-  if (mode != _P_OVERLAY || !rc)
-    ::cygheap->user.reimpersonate ();
+  if (mode != _P_OVERLAY)
+    SetHandleInformation (my_wr_proc_pipe, HANDLE_FLAG_INHERIT,
+                         HANDLE_FLAG_INHERIT);
 
   /* Set errno now so that debugging messages from it appear before our
      final debugging message [this is a general rule for debugging
@@ -748,9 +750,16 @@ loop:
         be closed otherwise.  Don't need to do this for 'parent' since it will
         be closed in every case.  See FIXME above. */
       if (!iscygwin () && mode == _P_OVERLAY)
-       SetHandleInformation (wr_proc_pipe, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
+       SetHandleInformation (wr_proc_pipe, HANDLE_FLAG_INHERIT,
+                             HANDLE_FLAG_INHERIT);
       if (wr_proc_pipe == my_wr_proc_pipe)
        wr_proc_pipe = NULL;    /* We still own it: don't nuke in destructor */
+
+      /* Restore impersonation. In case of _P_OVERLAY this isn't
+        allowed since it would overwrite child data. */
+      if (mode != _P_OVERLAY)
+       ::cygheap->user.reimpersonate ();
+
       res = -1;
       goto out;
     }
This page took 0.034032 seconds and 5 git commands to generate.