@@ -1697,12 +1697,12 @@ consult the installation file that came with this distribution, or visit \n\
1697
1697
}
1698
1698
script_file = estrdup (php_optarg );
1699
1699
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 ];
1703
1700
break ;
1704
1701
1705
1702
case 'i' : /* php info & quit */
1703
+ if (script_file ) {
1704
+ efree (script_file );
1705
+ }
1706
1706
if (php_request_startup (TSRMLS_C ) == FAILURE ) {
1707
1707
SG (server_context ) = NULL ;
1708
1708
php_module_shutdown (TSRMLS_C );
@@ -1723,6 +1723,9 @@ consult the installation file that came with this distribution, or visit \n\
1723
1723
break ;
1724
1724
1725
1725
case 'm' : /* list compiled in modules */
1726
+ if (script_file ) {
1727
+ efree (script_file );
1728
+ }
1726
1729
SG (headers_sent ) = 1 ;
1727
1730
php_printf ("[PHP Modules]\n" );
1728
1731
print_modules (TSRMLS_C );
@@ -1744,6 +1747,9 @@ consult the installation file that came with this distribution, or visit \n\
1744
1747
break ;
1745
1748
1746
1749
case 'v' : /* show php version & quit */
1750
+ if (script_file ) {
1751
+ efree (script_file );
1752
+ }
1747
1753
no_headers = 1 ;
1748
1754
if (php_request_startup (TSRMLS_C ) == FAILURE ) {
1749
1755
SG (server_context ) = NULL ;
@@ -1780,21 +1786,25 @@ consult the installation file that came with this distribution, or visit \n\
1780
1786
/* override path_translated if -f on command line */
1781
1787
STR_FREE (SG (request_info ).path_translated );
1782
1788
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 ];
1783
1801
}
1784
1802
1785
1803
if (no_headers ) {
1786
1804
SG (headers_sent ) = 1 ;
1787
1805
SG (request_info ).no_headers = 1 ;
1788
1806
}
1789
1807
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
-
1798
1808
/* all remaining arguments are part of the query string
1799
1809
this section of code concatenates all remaining arguments
1800
1810
into a single string, seperating args with a &
0 commit comments