@@ -2112,9 +2112,9 @@ consult the installation file that came with this distribution, or visit \n\
2112
2112
2113
2113
#else
2114
2114
if (children ) {
2115
- char * cmd_line ;
2115
+ wchar_t * cmd_line_tmp , cmd_line [PHP_WIN32_IOUTIL_MAXPATHLEN ];
2116
+ size_t cmd_line_len ;
2116
2117
char kid_buf [16 ];
2117
- char my_name [MAX_PATH ] = {0 };
2118
2118
int i ;
2119
2119
2120
2120
ZeroMemory (& kid_cgi_ps , sizeof (kid_cgi_ps ));
@@ -2125,8 +2125,25 @@ consult the installation file that came with this distribution, or visit \n\
2125
2125
/* kids will inherit the env, don't let them spawn */
2126
2126
SetEnvironmentVariable ("PHP_FCGI_CHILDREN" , NULL );
2127
2127
2128
- GetModuleFileName (NULL , my_name , MAX_PATH );
2129
- cmd_line = my_name ;
2128
+ /* The current command line is used as is. This should normally be no issue,
2129
+ even if there were some I/O redirection. If some issues turn out, an
2130
+ extra parsing might be needed here. */
2131
+ cmd_line_tmp = GetCommandLineW ();
2132
+ if (!cmd_line_tmp ) {
2133
+ DWORD err = GetLastError ();
2134
+ char * err_text = php_win32_error_to_msg (err );
2135
+
2136
+ fprintf (stderr , "unable to get current command line: [0x%08lx]: %s\n" , err , err_text );
2137
+
2138
+ goto parent_out ;
2139
+ }
2140
+
2141
+ cmd_line_len = wcslen (cmd_line_tmp );
2142
+ if (cmd_line_len > sizeof (cmd_line ) - 1 ) {
2143
+ fprintf (stderr , "command line is too long\n" );
2144
+ goto parent_out ;
2145
+ }
2146
+ memmove (cmd_line , cmd_line_tmp , (cmd_line_len + 1 )* sizeof (wchar_t ));
2130
2147
2131
2148
job = CreateJobObject (NULL , NULL );
2132
2149
if (!job ) {
@@ -2162,7 +2179,7 @@ consult the installation file that came with this distribution, or visit \n\
2162
2179
i = kids ;
2163
2180
while (0 < i -- ) {
2164
2181
PROCESS_INFORMATION pi ;
2165
- STARTUPINFO si ;
2182
+ STARTUPINFOW si ;
2166
2183
2167
2184
if (NULL != kid_cgi_ps [i ]) {
2168
2185
continue ;
@@ -2177,7 +2194,7 @@ consult the installation file that came with this distribution, or visit \n\
2177
2194
si .hStdInput = (HANDLE )_get_osfhandle (fcgi_fd );
2178
2195
si .hStdError = INVALID_HANDLE_VALUE ;
2179
2196
2180
- if (CreateProcess (NULL , cmd_line , NULL , NULL , TRUE, CREATE_NO_WINDOW , NULL , NULL , & si , & pi )) {
2197
+ if (CreateProcessW (NULL , cmd_line , NULL , NULL , TRUE, CREATE_NO_WINDOW , NULL , NULL , & si , & pi )) {
2181
2198
kid_cgi_ps [i ] = pi .hProcess ;
2182
2199
if (!AssignProcessToJobObject (job , pi .hProcess )) {
2183
2200
DWORD err = GetLastError ();
0 commit comments