@@ -1746,7 +1746,6 @@ int main(int argc, char *argv[])
1746
1746
int status = 0 ;
1747
1747
#endif
1748
1748
char * query_string ;
1749
- char * decoded_query_string ;
1750
1749
int skip_getopt = 0 ;
1751
1750
1752
1751
#if defined(SIGPIPE ) && defined(SIG_IGN )
@@ -1801,10 +1800,15 @@ int main(int argc, char *argv[])
1801
1800
* the executable. Ideally we skip argument parsing when we're in cgi or fastcgi mode,
1802
1801
* but that breaks PHP scripts on Linux with a hashbang: `#!/php-cgi -d option=value`.
1803
1802
* Therefore, this code only prevents passing arguments if the query string starts with a '-'.
1804
- * Similarly, scripts spawned in subprocesses on Windows may have the same issue. */
1803
+ * Similarly, scripts spawned in subprocesses on Windows may have the same issue.
1804
+ * However, Windows has lots of conversion rules and command line parsing rules that
1805
+ * are too difficult and dangerous to reliably emulate. */
1805
1806
if ((query_string = getenv ("QUERY_STRING" )) != NULL && strchr (query_string , '=' ) == NULL ) {
1807
+ #ifdef PHP_WIN32
1808
+ skip_getopt = cgi || fastcgi ;
1809
+ #else
1806
1810
unsigned char * p ;
1807
- decoded_query_string = strdup (query_string );
1811
+ char * decoded_query_string = strdup (query_string );
1808
1812
php_url_decode (decoded_query_string , strlen (decoded_query_string ));
1809
1813
for (p = (unsigned char * )decoded_query_string ; * p && * p <= ' ' ; p ++ ) {
1810
1814
/* skip all leading spaces */
@@ -1813,22 +1817,8 @@ int main(int argc, char *argv[])
1813
1817
skip_getopt = 1 ;
1814
1818
}
1815
1819
1816
- /* On Windows we have to take into account the "best fit" mapping behaviour. */
1817
- #ifdef PHP_WIN32
1818
- if (* p >= 0x80 ) {
1819
- wchar_t wide_buf [1 ];
1820
- wide_buf [0 ] = * p ;
1821
- char char_buf [4 ];
1822
- size_t wide_buf_len = sizeof (wide_buf ) / sizeof (wide_buf [0 ]);
1823
- size_t char_buf_len = sizeof (char_buf ) / sizeof (char_buf [0 ]);
1824
- if (WideCharToMultiByte (CP_ACP , 0 , wide_buf , wide_buf_len , char_buf , char_buf_len , NULL , NULL ) == 0
1825
- || char_buf [0 ] == '-' ) {
1826
- skip_getopt = 1 ;
1827
- }
1828
- }
1829
- #endif
1830
-
1831
1820
free (decoded_query_string );
1821
+ #endif
1832
1822
}
1833
1823
1834
1824
php_ini_builder_init (& ini_builder );
@@ -1895,18 +1885,17 @@ int main(int argc, char *argv[])
1895
1885
1896
1886
/* check force_cgi after startup, so we have proper output */
1897
1887
if (cgi && CGIG (force_redirect )) {
1898
- /* Apache will generate REDIRECT_STATUS,
1899
- * Netscape and redirect.so will generate HTTP_REDIRECT_STATUS.
1900
- * redirect.so and installation instructions available from
1901
- * http://www.koehntopp.de/php.
1902
- * -- kk@netuse.de
1903
- */
1904
- if (!getenv ("REDIRECT_STATUS" ) &&
1905
- !getenv ("HTTP_REDIRECT_STATUS" ) &&
1906
- /* this is to allow a different env var to be configured
1907
- * in case some server does something different than above */
1908
- (!CGIG (redirect_status_env ) || !getenv (CGIG (redirect_status_env )))
1909
- ) {
1888
+ /* This is to allow a different environment variable to be configured
1889
+ * in case the we cannot auto-detect which environment variable to use.
1890
+ * Checking this first to allow user overrides in case the environment
1891
+ * variable can be set by an untrusted party. */
1892
+ const char * redirect_status_env = CGIG (redirect_status_env );
1893
+ if (!redirect_status_env ) {
1894
+ /* Apache will generate REDIRECT_STATUS. */
1895
+ redirect_status_env = "REDIRECT_STATUS" ;
1896
+ }
1897
+
1898
+ if (!getenv (redirect_status_env )) {
1910
1899
zend_try {
1911
1900
SG (sapi_headers ).http_response_code = 400 ;
1912
1901
PUTS ("<b>Security Alert!</b> The PHP CGI cannot be accessed directly.\n\n\
0 commit comments