Skip to content

Commit e65760f

Browse files
committed
Fixed bug #73904 php-cgi fails to load -c specified php.ini file
1 parent 6fbd61a commit e65760f

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

sapi/cgi/cgi_main.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,9 +2112,9 @@ consult the installation file that came with this distribution, or visit \n\
21122112

21132113
#else
21142114
if (children) {
2115-
char *cmd_line;
2115+
wchar_t *cmd_line_tmp, cmd_line[PHP_WIN32_IOUTIL_MAXPATHLEN];
2116+
size_t cmd_line_len;
21162117
char kid_buf[16];
2117-
char my_name[MAX_PATH] = {0};
21182118
int i;
21192119

21202120
ZeroMemory(&kid_cgi_ps, sizeof(kid_cgi_ps));
@@ -2125,8 +2125,25 @@ consult the installation file that came with this distribution, or visit \n\
21252125
/* kids will inherit the env, don't let them spawn */
21262126
SetEnvironmentVariable("PHP_FCGI_CHILDREN", NULL);
21272127

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));
21302147

21312148
job = CreateJobObject(NULL, NULL);
21322149
if (!job) {
@@ -2162,7 +2179,7 @@ consult the installation file that came with this distribution, or visit \n\
21622179
i = kids;
21632180
while (0 < i--) {
21642181
PROCESS_INFORMATION pi;
2165-
STARTUPINFO si;
2182+
STARTUPINFOW si;
21662183

21672184
if (NULL != kid_cgi_ps[i]) {
21682185
continue;
@@ -2177,7 +2194,7 @@ consult the installation file that came with this distribution, or visit \n\
21772194
si.hStdInput = (HANDLE)_get_osfhandle(fcgi_fd);
21782195
si.hStdError = INVALID_HANDLE_VALUE;
21792196

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)) {
21812198
kid_cgi_ps[i] = pi.hProcess;
21822199
if (!AssignProcessToJobObject(job, pi.hProcess)) {
21832200
DWORD err = GetLastError();

0 commit comments

Comments
 (0)