com php-src: Fixed bug #73904 php-cgi fails to load -c specified php.ini file: sapi/cgi/cgi_main.c
| From: | Anatol Belski | Date: | Thu, 12 Jan 2017 16:25:26 +0000 |
| Subject: | com php-src: Fixed bug #73904 php-cgi fails to load -c specified php.ini file: sapi/cgi/cgi_main.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-96696@lists.php.net to get a copy of this message | ||
Commit: e65760f878a116d7ffc858c5a0e30f6075230443
Author: Anatol Belski <ab@php.net> Thu, 12 Jan 2017 17:25:26 +0100
Parents: 6fbd61a8199fbac9aac25d0dfaf1402a8f2b4e7b
Branches: PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e65760f878a116d7ffc858c5a0e30f6075230443
Log:
Fixed bug #73904 php-cgi fails to load -c specified php.ini file
Bugs:
https://bugs.php.net/73904
Changed paths:
M sapi/cgi/cgi_main.c
Diff:
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index 2461528..ede7199 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -2112,9 +2112,9 @@ consult the installation file that came with this distribution, or visit \n\
#else
if (children) {
- char *cmd_line;
+ wchar_t *cmd_line_tmp, cmd_line[PHP_WIN32_IOUTIL_MAXPATHLEN];
+ size_t cmd_line_len;
char kid_buf[16];
- char my_name[MAX_PATH] = {0};
int i;
ZeroMemory(&kid_cgi_ps, sizeof(kid_cgi_ps));
@@ -2125,8 +2125,25 @@ consult the installation file that came with this distribution, or visit \n\
/* kids will inherit the env, don't let them spawn */
SetEnvironmentVariable("PHP_FCGI_CHILDREN", NULL);
- GetModuleFileName(NULL, my_name, MAX_PATH);
- cmd_line = my_name;
+ /* The current command line is used as is. This should normally be no issue,
+ even if there were some I/O redirection. If some issues turn out, an
+ extra parsing might be needed here. */
+ cmd_line_tmp = GetCommandLineW();
+ if (!cmd_line_tmp) {
+ DWORD err = GetLastError();
+ char *err_text = php_win32_error_to_msg(err);
+
+ fprintf(stderr, "unable to get current command line: [0x%08lx]: %s\n", err,
err_text);
+
+ goto parent_out;
+ }
+
+ cmd_line_len = wcslen(cmd_line_tmp);
+ if (cmd_line_len > sizeof(cmd_line) - 1) {
+ fprintf(stderr, "command line is too long\n");
+ goto parent_out;
+ }
+ memmove(cmd_line, cmd_line_tmp, (cmd_line_len + 1)*sizeof(wchar_t));
job = CreateJobObject(NULL, NULL);
if (!job) {
@@ -2162,7 +2179,7 @@ consult the installation file that came with this distribution, or visit \n\
i = kids;
while (0 < i--) {
PROCESS_INFORMATION pi;
- STARTUPINFO si;
+ STARTUPINFOW si;
if (NULL != kid_cgi_ps[i]) {
continue;
@@ -2177,7 +2194,7 @@ consult the installation file that came with this distribution, or visit \n\
si.hStdInput = (HANDLE)_get_osfhandle(fcgi_fd);
si.hStdError = INVALID_HANDLE_VALUE;
- if (CreateProcess(NULL, cmd_line, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si,
&pi)) {
+ if (CreateProcessW(NULL, cmd_line, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si,
&pi)) {
kid_cgi_ps[i] = pi.hProcess;
if (!AssignProcessToJobObject(job, pi.hProcess)) {
DWORD err = GetLastError();