Skip to content

Commit e54f020

Browse files
committed
The -f option is fixed to work in the same way as in CLI sapi
1 parent 91ea43e commit e54f020

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

sapi/cgi/cgi_main.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,12 +1697,12 @@ consult the installation file that came with this distribution, or visit \n\
16971697
}
16981698
script_file = estrdup(php_optarg);
16991699
no_headers = 1;
1700-
/* arguments after the file are considered script args */
1701-
SG(request_info).argc = argc - (php_optind - 1);
1702-
SG(request_info).argv = &argv[php_optind - 1];
17031700
break;
17041701

17051702
case 'i': /* php info & quit */
1703+
if (script_file) {
1704+
efree(script_file);
1705+
}
17061706
if (php_request_startup(TSRMLS_C) == FAILURE) {
17071707
SG(server_context) = NULL;
17081708
php_module_shutdown(TSRMLS_C);
@@ -1723,6 +1723,9 @@ consult the installation file that came with this distribution, or visit \n\
17231723
break;
17241724

17251725
case 'm': /* list compiled in modules */
1726+
if (script_file) {
1727+
efree(script_file);
1728+
}
17261729
SG(headers_sent) = 1;
17271730
php_printf("[PHP Modules]\n");
17281731
print_modules(TSRMLS_C);
@@ -1744,6 +1747,9 @@ consult the installation file that came with this distribution, or visit \n\
17441747
break;
17451748

17461749
case 'v': /* show php version & quit */
1750+
if (script_file) {
1751+
efree(script_file);
1752+
}
17471753
no_headers = 1;
17481754
if (php_request_startup(TSRMLS_C) == FAILURE) {
17491755
SG(server_context) = NULL;
@@ -1780,21 +1786,25 @@ consult the installation file that came with this distribution, or visit \n\
17801786
/* override path_translated if -f on command line */
17811787
STR_FREE(SG(request_info).path_translated);
17821788
SG(request_info).path_translated = script_file;
1789+
/* before registering argv to module exchange the *new* argv[0] */
1790+
/* we can achieve this without allocating more memory */
1791+
SG(request_info).argc = argc - (php_optind - 1);
1792+
SG(request_info).argv = &argv[php_optind - 1];
1793+
SG(request_info).argv[0] = script_file;
1794+
} else if (argc > php_optind) {
1795+
/* file is on command line, but not in -f opt */
1796+
STR_FREE(SG(request_info).path_translated);
1797+
SG(request_info).path_translated = estrdup(argv[php_optind++]);
1798+
/* arguments after the file are considered script args */
1799+
SG(request_info).argc = argc - php_optind;
1800+
SG(request_info).argv = &argv[php_optind];
17831801
}
17841802

17851803
if (no_headers) {
17861804
SG(headers_sent) = 1;
17871805
SG(request_info).no_headers = 1;
17881806
}
17891807

1790-
if (!SG(request_info).path_translated && argc > php_optind) {
1791-
/* arguments after the file are considered script args */
1792-
SG(request_info).argc = argc - php_optind;
1793-
SG(request_info).argv = &argv[php_optind];
1794-
/* file is on command line, but not in -f opt */
1795-
SG(request_info).path_translated = estrdup(argv[php_optind++]);
1796-
}
1797-
17981808
/* all remaining arguments are part of the query string
17991809
this section of code concatenates all remaining arguments
18001810
into a single string, seperating args with a &

0 commit comments

Comments
 (0)