Ticket #2650: avoid-race-condition-causing-child-processes-to-inherit-handles-unwantedly.dpatch

File avoid-race-condition-causing-child-processes-to-inherit-handles-unwantedly.dpatch, 3.4 KB (added by Deewiant, 5 years ago)

Haven't found a test case for this yet

Line 
1Sat Feb 14 00:55:17 FLE Standard Time 2009  Matti Niemenmaa <matti.niemenmaa+darcs@iki.fi>
2  * Avoid race condition causing child processes to inherit handles unwantedly
3 
4  The changes are based on the first alternative outlined in the 'resolution'
5  section at http://support.microsoft.com/kb/315939.
6
7New patches:
8
9[Avoid race condition causing child processes to inherit handles unwantedly
10Matti Niemenmaa <matti.niemenmaa+darcs@iki.fi>**20090213225517
11 
12 The changes are based on the first alternative outlined in the 'resolution'
13 section at http://support.microsoft.com/kb/315939.
14] {
15hunk ./cbits/runProcess.c 265
16-       HANDLE hTemporaryIn  = NULL;
17-       HANDLE hTemporaryOut = NULL;
18hunk ./cbits/runProcess.c 266
19-       SECURITY_ATTRIBUTES sec_attrs;
20hunk ./cbits/runProcess.c 267
21-       /* Create inheritable security attributes */
22-       sec_attrs.nLength = sizeof(SECURITY_ATTRIBUTES);
23-       sec_attrs.lpSecurityDescriptor = NULL;
24-       sec_attrs.bInheritHandle = TRUE;
25-
26-       /* Create the anon pipe with both ends inheritable */
27-       if (!CreatePipe(&hTemporaryIn, &hTemporaryOut, &sec_attrs, 0))
28+       /* Create the anon pipe as noninheritable initially */
29+       if (!CreatePipe(pHandleIn, pHandleOut, NULL, 0))
30hunk ./cbits/runProcess.c 277
31-               *pHandleIn = hTemporaryIn;
32-       else
33hunk ./cbits/runProcess.c 278
34-               /* Make the read end non-inheritable */
35-               status = DuplicateHandle(GetCurrentProcess(), hTemporaryIn,
36-                             GetCurrentProcess(), pHandleIn,
37-                             0,
38-                             FALSE, /* non-inheritable */
39-                             DUPLICATE_SAME_ACCESS);
40-               CloseHandle(hTemporaryIn);
41+               status = SetHandleInformation(*pHandleIn, HANDLE_FLAG_INHERIT,
42+                                                         HANDLE_FLAG_INHERIT);
43hunk ./cbits/runProcess.c 281
44-               {
45-                       maperrno();
46-                       *pHandleIn  = NULL;
47-                       *pHandleOut = NULL;
48-                       CloseHandle(hTemporaryOut);
49-                       return FALSE;
50-               }
51+                       goto cleanup_err;
52hunk ./cbits/runProcess.c 285
53-               *pHandleOut = hTemporaryOut;
54-       else
55hunk ./cbits/runProcess.c 286
56-               /* Make the write end non-inheritable */
57-               status = DuplicateHandle(GetCurrentProcess(), hTemporaryOut,
58-                             GetCurrentProcess(), pHandleOut,
59-                             0,
60-                             FALSE, /* non-inheritable */
61-                             DUPLICATE_SAME_ACCESS);
62-               CloseHandle(hTemporaryOut);
63+               status = SetHandleInformation(*pHandleOut, HANDLE_FLAG_INHERIT,
64+                                                          HANDLE_FLAG_INHERIT);
65hunk ./cbits/runProcess.c 289
66-               {
67-                       maperrno();
68-                       *pHandleIn  = NULL;
69-                       *pHandleOut = NULL;
70-                       CloseHandle(*pHandleIn);
71-               return FALSE;
72-       }
73+                       goto cleanup_err;
74hunk ./cbits/runProcess.c 293
75+
76+cleanup_err:
77+       maperrno();
78+       CloseHandle(*pHandleIn);
79+       CloseHandle(*pHandleOut);
80+       *pHandleIn  = NULL;
81+       *pHandleOut = NULL;
82+       return FALSE;
83hunk ./cbits/runProcess.c 308
84+       CRITICAL_SECTION crit;
85hunk ./cbits/runProcess.c 320
86+       InitializeCriticalSection(&crit);
87+       EnterCriticalSection(&crit);
88+
89hunk ./cbits/runProcess.c 411
90+
91+        LeaveCriticalSection(&crit);
92+        DeleteCriticalSection(&crit);
93+
94hunk ./cbits/runProcess.c 424
95+
96+        LeaveCriticalSection(&crit);
97+        DeleteCriticalSection(&crit);
98+
99}
100
101Context:
102
103[TAG process 1.0.1.0
104Ian Lynagh <igloo@earth.li>**20081212144852]
105[TAG GHC 6.10.1 release
106Ian Lynagh <igloo@earth.li>**20081107191824]
107[Bump version number to 1.0.1.0
108Ian Lynagh <igloo@earth.li>**20080920160210]
109[TAG 6.10 branch has been forked
110Ian Lynagh <igloo@earth.li>**20080919123438]
111[TAG GHC 6.10 fork
112Ian Lynagh <igloo@earth.li>**20080919005047]
113Patch bundle hash:
1146ceeeac8709367b581d7b588f1f8c58a3b7a5f7b