@@ -131,14 +131,6 @@ static size_t nsapi_client_size = sizeof(nsapi_client)/sizeof(nsapi_client[0]);
131
131
/* this parameters to "Service"/"Error" are NSAPI ones which should not be php.ini keys and are excluded */
132
132
static char * nsapi_exclude_from_ini_entries [] = { "fn" , "type" , "method" , "directive" , "code" , "reason" , "script" , "bucket" , NULL };
133
133
134
- static char * nsapi_strdup (char * str )
135
- {
136
- if (str != NULL ) {
137
- return STRDUP (str );
138
- }
139
- return NULL ;
140
- }
141
-
142
134
static void nsapi_free (void * addr )
143
135
{
144
136
if (addr != NULL ) {
@@ -500,7 +492,7 @@ static int php_nsapi_remove_header(sapi_header_struct *sapi_header TSRMLS_DC)
500
492
nsapi_request_context * rc = (nsapi_request_context * )SG (server_context );
501
493
502
494
/* copy the header, because NSAPI needs reformatting and we do not want to change the parameter */
503
- header_name = nsapi_strdup ( sapi_header -> header );
495
+ header_name = pool_strdup ( rc -> sn -> pool , sapi_header -> header );
504
496
505
497
/* extract name, this works, if only the header without ':' is given, too */
506
498
if (p = strchr (header_name , ':' )) {
@@ -514,7 +506,7 @@ static int php_nsapi_remove_header(sapi_header_struct *sapi_header TSRMLS_DC)
514
506
515
507
/* remove the header */
516
508
param_free (pblock_remove (header_name , rc -> rq -> srvhdrs ));
517
- nsapi_free ( header_name );
509
+ pool_free ( rc -> sn -> pool , header_name );
518
510
519
511
return ZEND_HASH_APPLY_KEEP ;
520
512
}
@@ -538,7 +530,7 @@ static int sapi_nsapi_header_handler(sapi_header_struct *sapi_header, sapi_heade
538
530
case SAPI_HEADER_ADD :
539
531
case SAPI_HEADER_REPLACE :
540
532
/* copy the header, because NSAPI needs reformatting and we do not want to change the parameter */
541
- header_name = nsapi_strdup ( sapi_header -> header );
533
+ header_name = pool_strdup ( rc -> sn -> pool , sapi_header -> header );
542
534
543
535
/* split header and align pointer for content */
544
536
header_content = strchr (header_name , ':' );
@@ -561,7 +553,7 @@ static int sapi_nsapi_header_handler(sapi_header_struct *sapi_header, sapi_heade
561
553
pblock_nvinsert (header_name , header_content , rc -> rq -> srvhdrs );
562
554
}
563
555
564
- nsapi_free ( header_name );
556
+ pool_free ( rc -> sn -> pool , header_name );
565
557
return SAPI_HEADER_ADD ;
566
558
567
559
default :
@@ -750,28 +742,25 @@ static void sapi_nsapi_register_server_variables(zval *track_vars_array TSRMLS_D
750
742
751
743
/* Create full Request-URI & Script-Name */
752
744
if (SG (request_info ).request_uri ) {
745
+ pos = strlen (SG (request_info ).request_uri );
746
+
753
747
if (SG (request_info ).query_string ) {
754
748
spprintf (& value , 0 , "%s?%s" , SG (request_info ).request_uri , SG (request_info ).query_string );
755
749
if (value ) {
756
750
php_register_variable ("REQUEST_URI" , value , track_vars_array TSRMLS_CC );
757
751
efree (value );
758
752
}
759
753
} else {
760
- php_register_variable ("REQUEST_URI" , SG (request_info ).request_uri , track_vars_array TSRMLS_CC );
754
+ php_register_variable_safe ("REQUEST_URI" , SG (request_info ).request_uri , pos , track_vars_array TSRMLS_CC );
761
755
}
762
756
763
- if (value = nsapi_strdup (SG (request_info ).request_uri )) {
764
- if (rc -> path_info ) {
765
- pos = strlen (SG (request_info ).request_uri ) - strlen (rc -> path_info );
766
- if (pos >=0 ) {
767
- value [pos ] = '\0' ;
768
- } else {
769
- value [0 ]= '\0' ;
770
- }
757
+ if (rc -> path_info ) {
758
+ pos -= strlen (rc -> path_info );
759
+ if (pos < 0 ) {
760
+ pos = 0 ;
771
761
}
772
- php_register_variable ("SCRIPT_NAME" , value , track_vars_array TSRMLS_CC );
773
- nsapi_free (value );
774
762
}
763
+ php_register_variable_safe ("SCRIPT_NAME" , SG (request_info ).request_uri , pos , track_vars_array TSRMLS_CC );
775
764
}
776
765
php_register_variable ("SCRIPT_FILENAME" , SG (request_info ).path_translated , track_vars_array TSRMLS_CC );
777
766
@@ -1014,21 +1003,25 @@ int NSAPI_PUBLIC php5_execute(pblock *pb, Session *sn, Request *rq)
1014
1003
}
1015
1004
}
1016
1005
1017
- request_context = (nsapi_request_context * )MALLOC (sizeof (nsapi_request_context ));
1006
+ request_context = (nsapi_request_context * )pool_malloc (sn -> pool , sizeof (nsapi_request_context ));
1007
+ if (!request_context ) {
1008
+ log_error (LOG_CATASTROPHE , pblock_findval ("fn" , pb ), sn , rq , "Insufficient memory to process PHP request!" );
1009
+ return REQ_ABORTED ;
1010
+ }
1018
1011
request_context -> pb = pb ;
1019
1012
request_context -> sn = sn ;
1020
1013
request_context -> rq = rq ;
1021
1014
request_context -> read_post_bytes = 0 ;
1022
1015
request_context -> fixed_script = fixed_script ;
1023
1016
request_context -> http_error = (error_directive ) ? rq -> status_num : 0 ;
1024
- request_context -> path_info = nsapi_strdup ( path_info ) ;
1017
+ request_context -> path_info = path_info ;
1025
1018
1026
1019
SG (server_context ) = request_context ;
1027
- SG (request_info ).query_string = nsapi_strdup ( query_string ) ;
1028
- SG (request_info ).request_uri = nsapi_strdup ( uri ) ;
1029
- SG (request_info ).request_method = nsapi_strdup ( request_method ) ;
1030
- SG (request_info ).path_translated = nsapi_strdup ( path_translated ) ;
1031
- SG (request_info ).content_type = nsapi_strdup ( content_type ) ;
1020
+ SG (request_info ).query_string = query_string ;
1021
+ SG (request_info ).request_uri = uri ;
1022
+ SG (request_info ).request_method = request_method ;
1023
+ SG (request_info ).path_translated = path_translated ;
1024
+ SG (request_info ).content_type = content_type ;
1032
1025
SG (request_info ).content_length = (content_length == NULL ) ? 0 : strtoul (content_length , 0 , 0 );
1033
1026
SG (sapi_headers ).http_response_code = (error_directive ) ? rq -> status_num : 200 ;
1034
1027
@@ -1068,14 +1061,7 @@ int NSAPI_PUBLIC php5_execute(pblock *pb, Session *sn, Request *rq)
1068
1061
}
1069
1062
}
1070
1063
1071
- nsapi_free (request_context -> path_info );
1072
- nsapi_free (SG (request_info ).query_string );
1073
- nsapi_free (SG (request_info ).request_uri );
1074
- nsapi_free ((void * )(SG (request_info ).request_method ));
1075
- nsapi_free (SG (request_info ).path_translated );
1076
- nsapi_free ((void * )(SG (request_info ).content_type ));
1077
-
1078
- FREE (request_context );
1064
+ pool_free (sn -> pool , request_context );
1079
1065
SG (server_context ) = NULL ;
1080
1066
1081
1067
return retval ;
0 commit comments