@@ -587,6 +587,17 @@ static char *sapi_cgi_read_cookies(TSRMLS_D)
587
587
return sapi_cgibin_getenv ((char * ) "HTTP_COOKIE" , sizeof ("HTTP_COOKIE" )- 1 TSRMLS_CC );
588
588
}
589
589
590
+ static void cgi_php_load_env_var (char * var , unsigned int var_len , char * val , unsigned int val_len , void * arg )
591
+ {
592
+ zval * array_ptr = (zval * )arg ;
593
+ int filter_arg = (array_ptr == PG (http_globals )[TRACK_VARS_ENV ])?PARSE_ENV :PARSE_SERVER ;
594
+ unsigned int new_val_len ;
595
+
596
+ if (sapi_module .input_filter (filter_arg , var , & val , strlen (val ), & new_val_len TSRMLS_CC )) {
597
+ php_register_variable_safe (var , val , new_val_len , array_ptr TSRMLS_CC );
598
+ }
599
+ }
600
+
590
601
void cgi_php_import_environment_variables (zval * array_ptr TSRMLS_DC )
591
602
{
592
603
if (PG (http_globals )[TRACK_VARS_ENV ] &&
@@ -616,26 +627,11 @@ void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC)
616
627
617
628
if (fcgi_is_fastcgi ()) {
618
629
fcgi_request * request = (fcgi_request * ) SG (server_context );
619
- HashPosition pos ;
620
630
int magic_quotes_gpc = PG (magic_quotes_gpc );
621
- char * var , * * val ;
622
- uint var_len ;
623
- ulong idx ;
624
- int filter_arg = (array_ptr == PG (http_globals )[TRACK_VARS_ENV ])?PARSE_ENV :PARSE_SERVER ;
625
631
626
632
/* turn off magic_quotes while importing environment variables */
627
633
PG (magic_quotes_gpc ) = 0 ;
628
- for (zend_hash_internal_pointer_reset_ex (& request -> env , & pos );
629
- zend_hash_get_current_key_ex (& request -> env , & var , & var_len , & idx , 0 , & pos ) == HASH_KEY_IS_STRING &&
630
- zend_hash_get_current_data_ex (& request -> env , (void * * ) & val , & pos ) == SUCCESS ;
631
- zend_hash_move_forward_ex (& request -> env , & pos )
632
- ) {
633
- unsigned int new_val_len ;
634
-
635
- if (sapi_module .input_filter (filter_arg , var , val , strlen (* val ), & new_val_len TSRMLS_CC )) {
636
- php_register_variable_safe (var , * val , new_val_len , array_ptr TSRMLS_CC );
637
- }
638
- }
634
+ fcgi_loadenv (request , cgi_php_load_env_var , array_ptr );
639
635
PG (magic_quotes_gpc ) = magic_quotes_gpc ;
640
636
}
641
637
}
@@ -1100,8 +1096,10 @@ static void init_request_info(TSRMLS_D)
1100
1096
char * env_path_info = sapi_cgibin_getenv ("PATH_INFO" , sizeof ("PATH_INFO" )- 1 TSRMLS_CC );
1101
1097
char * env_script_name = sapi_cgibin_getenv ("SCRIPT_NAME" , sizeof ("SCRIPT_NAME" )- 1 TSRMLS_CC );
1102
1098
1099
+ #ifdef PHP_WIN32
1103
1100
/* Hack for buggy IIS that sets incorrect PATH_INFO */
1104
1101
char * env_server_software = sapi_cgibin_getenv ("SERVER_SOFTWARE" , sizeof ("SERVER_SOFTWARE" )- 1 TSRMLS_CC );
1102
+
1105
1103
if (env_server_software &&
1106
1104
env_script_name &&
1107
1105
env_path_info &&
@@ -1115,6 +1113,7 @@ static void init_request_info(TSRMLS_D)
1115
1113
}
1116
1114
env_path_info = _sapi_cgibin_putenv ("PATH_INFO" , env_path_info TSRMLS_CC );
1117
1115
}
1116
+ #endif
1118
1117
1119
1118
if (CGIG (fix_pathinfo )) {
1120
1119
struct stat st ;
@@ -1488,7 +1487,7 @@ int main(int argc, char *argv[])
1488
1487
int fastcgi = fcgi_is_fastcgi ();
1489
1488
char * bindpath = NULL ;
1490
1489
int fcgi_fd = 0 ;
1491
- fcgi_request request ;
1490
+ fcgi_request * request = NULL ;
1492
1491
int repeats = 1 ;
1493
1492
int benchmark = 0 ;
1494
1493
#if HAVE_GETTIMEOFDAY
@@ -1689,7 +1688,7 @@ consult the installation file that came with this distribution, or visit \n\
1689
1688
php_import_environment_variables = cgi_php_import_environment_variables ;
1690
1689
1691
1690
/* library is already initialized, now init our request */
1692
- fcgi_init_request ( & request , fcgi_fd );
1691
+ request = fcgi_init_request ( fcgi_fd );
1693
1692
1694
1693
#ifndef PHP_WIN32
1695
1694
/* Pre-fork, if required */
@@ -1810,6 +1809,9 @@ consult the installation file that came with this distribution, or visit \n\
1810
1809
break ;
1811
1810
case 'h' :
1812
1811
case '?' :
1812
+ if (request ) {
1813
+ fcgi_destroy_request (request );
1814
+ }
1813
1815
fcgi_shutdown ();
1814
1816
no_headers = 1 ;
1815
1817
SG (headers_sent ) = 1 ;
@@ -1831,8 +1833,8 @@ consult the installation file that came with this distribution, or visit \n\
1831
1833
fcgi_impersonate ();
1832
1834
}
1833
1835
#endif
1834
- while (!fastcgi || fcgi_accept_request (& request ) >= 0 ) {
1835
- SG (server_context ) = (void * ) & request ;
1836
+ while (!fastcgi || fcgi_accept_request (request ) >= 0 ) {
1837
+ SG (server_context ) = fastcgi ? (void * ) request : ( void * ) 1 ;
1836
1838
init_request_info (TSRMLS_C );
1837
1839
CG (interactive ) = 0 ;
1838
1840
@@ -2026,7 +2028,7 @@ consult the installation file that came with this distribution, or visit \n\
2026
2028
* get path_translated */
2027
2029
if (php_request_startup (TSRMLS_C ) == FAILURE ) {
2028
2030
if (fastcgi ) {
2029
- fcgi_finish_request (& request , 1 );
2031
+ fcgi_finish_request (request , 1 );
2030
2032
}
2031
2033
SG (server_context ) = NULL ;
2032
2034
php_module_shutdown (TSRMLS_C );
@@ -2232,7 +2234,7 @@ consult the installation file that came with this distribution, or visit \n\
2232
2234
/* only fastcgi will get here */
2233
2235
requests ++ ;
2234
2236
if (max_requests && (requests == max_requests )) {
2235
- fcgi_finish_request (& request , 1 );
2237
+ fcgi_finish_request (request , 1 );
2236
2238
if (bindpath ) {
2237
2239
free (bindpath );
2238
2240
}
@@ -2244,6 +2246,9 @@ consult the installation file that came with this distribution, or visit \n\
2244
2246
}
2245
2247
/* end of fastcgi loop */
2246
2248
}
2249
+ if (request ) {
2250
+ fcgi_destroy_request (request );
2251
+ }
2247
2252
fcgi_shutdown ();
2248
2253
2249
2254
if (cgi_sapi_module .php_ini_path_override ) {
0 commit comments