components/php-5_2/php-sapi/patches/10_php_perf_nsapi.c.patch
changeset 461 edabdd6aff23
equal deleted inserted replaced
460:aded0f0f9594 461:edabdd6aff23
       
     1 Index: php-5.2.11/sapi/nsapi/nsapi.c
       
     2 ===================================================================
       
     3 --- php-5.2.11/sapi/nsapi/nsapi.c	(revision 291216)
       
     4 +++ php-5.2.11/sapi/nsapi/nsapi.c	(working copy)
       
     5 @@ -131,14 +131,6 @@
       
     6  /* this parameters to "Service"/"Error" are NSAPI ones which should not be php.ini keys and are excluded */
       
     7  static char *nsapi_exclude_from_ini_entries[] = { "fn", "type", "method", "directive", "code", "reason", "script", "bucket", NULL };
       
     8  
       
     9 -static char *nsapi_strdup(char *str)
       
    10 -{
       
    11 -	if (str != NULL) {
       
    12 -		return STRDUP(str);
       
    13 -	}
       
    14 -	return NULL;
       
    15 -}
       
    16 -
       
    17  static void nsapi_free(void *addr)
       
    18  {
       
    19  	if (addr != NULL) {
       
    20 @@ -485,7 +477,7 @@
       
    21  	char *header_name, *header_content, *p;
       
    22  	nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
       
    23  
       
    24 -	header_name = nsapi_strdup(sapi_header->header);
       
    25 +	header_name = pool_strdup(rc->sn->pool, sapi_header->header);
       
    26  	header_content = p = strchr(header_name, ':');
       
    27  	if (p == NULL) {
       
    28  		efree(sapi_header->header);
       
    29 @@ -509,7 +501,7 @@
       
    30  		pblock_nvinsert(header_name, header_content, rc->rq->srvhdrs);
       
    31  	}
       
    32  
       
    33 -	nsapi_free(header_name);
       
    34 +	pool_free(rc->sn->pool, header_name);
       
    35  
       
    36  	return SAPI_HEADER_ADD;
       
    37  }
       
    38 @@ -679,8 +671,8 @@
       
    39  
       
    40  	/* DOCUMENT_ROOT */
       
    41  	if (value = request_translate_uri("/", rc->sn)) {
       
    42 -	  	value[strlen(value) - 1] = '\0';
       
    43 -		php_register_variable("DOCUMENT_ROOT", value, track_vars_array TSRMLS_CC);
       
    44 +		pos = strlen(value);
       
    45 +		php_register_variable_safe("DOCUMENT_ROOT", value, pos-1, track_vars_array TSRMLS_CC);
       
    46  		nsapi_free(value);
       
    47  	}
       
    48  
       
    49 @@ -695,6 +687,8 @@
       
    50  
       
    51  	/* Create full Request-URI & Script-Name */
       
    52  	if (SG(request_info).request_uri) {
       
    53 +		pos = strlen(SG(request_info).request_uri);
       
    54 +		
       
    55  		if (SG(request_info).query_string) {
       
    56  			spprintf(&value, 0, "%s?%s", SG(request_info).request_uri, SG(request_info).query_string);
       
    57  			if (value) {
       
    58 @@ -702,21 +696,16 @@
       
    59  				efree(value);
       
    60  			}
       
    61  		} else {
       
    62 -			php_register_variable("REQUEST_URI", SG(request_info).request_uri, track_vars_array TSRMLS_CC);
       
    63 +			php_register_variable_safe("REQUEST_URI", SG(request_info).request_uri, pos, track_vars_array TSRMLS_CC);
       
    64  		}
       
    65  
       
    66 -		if (value = nsapi_strdup(SG(request_info).request_uri)) {
       
    67 -			if (rc->path_info) {
       
    68 -				pos = strlen(SG(request_info).request_uri) - strlen(rc->path_info);
       
    69 -				if (pos>=0) {
       
    70 -					value[pos] = '\0';
       
    71 -				} else {
       
    72 -					value[0]='\0';
       
    73 -				}
       
    74 +		if (rc->path_info) {
       
    75 +			pos -= strlen(rc->path_info);
       
    76 +			if (pos<0) {
       
    77 +				pos = 0;
       
    78  			}
       
    79 -			php_register_variable("SCRIPT_NAME", value, track_vars_array TSRMLS_CC);
       
    80 -			nsapi_free(value);
       
    81  		}
       
    82 +		php_register_variable_safe("SCRIPT_NAME", SG(request_info).request_uri, pos, track_vars_array TSRMLS_CC);
       
    83  	}
       
    84  	php_register_variable("SCRIPT_FILENAME", SG(request_info).path_translated, track_vars_array TSRMLS_CC);
       
    85  
       
    86 @@ -958,21 +947,25 @@
       
    87  		}
       
    88  	}
       
    89  
       
    90 -	request_context = (nsapi_request_context *)MALLOC(sizeof(nsapi_request_context));
       
    91 +	request_context = (nsapi_request_context *)pool_malloc(sn->pool, sizeof(nsapi_request_context));
       
    92 +	if (!request_context) {
       
    93 +		log_error(LOG_CATASTROPHE, pblock_findval("fn", pb), sn, rq, "Insufficient memory to process PHP request!");
       
    94 +		return REQ_ABORTED;
       
    95 +	}
       
    96  	request_context->pb = pb;
       
    97  	request_context->sn = sn;
       
    98  	request_context->rq = rq;
       
    99  	request_context->read_post_bytes = 0;
       
   100  	request_context->fixed_script = fixed_script;
       
   101  	request_context->http_error = (error_directive) ? rq->status_num : 0;
       
   102 -	request_context->path_info = nsapi_strdup(path_info);
       
   103 +	request_context->path_info = path_info;
       
   104  
       
   105  	SG(server_context) = request_context;
       
   106 -	SG(request_info).query_string = nsapi_strdup(query_string);
       
   107 -	SG(request_info).request_uri = nsapi_strdup(uri);
       
   108 -	SG(request_info).request_method = nsapi_strdup(request_method);
       
   109 -	SG(request_info).path_translated = nsapi_strdup(path_translated);
       
   110 -	SG(request_info).content_type = nsapi_strdup(content_type);
       
   111 +	SG(request_info).query_string = query_string;
       
   112 +	SG(request_info).request_uri = uri;
       
   113 +	SG(request_info).request_method = request_method;
       
   114 +	SG(request_info).path_translated = path_translated;
       
   115 +	SG(request_info).content_type = content_type;
       
   116  	SG(request_info).content_length = (content_length == NULL) ? 0 : strtoul(content_length, 0, 0);
       
   117  	SG(sapi_headers).http_response_code = (error_directive) ? rq->status_num : 200;
       
   118  	
       
   119 @@ -1012,14 +1005,7 @@
       
   120  		}
       
   121  	}
       
   122  
       
   123 -	nsapi_free(request_context->path_info);
       
   124 -	nsapi_free(SG(request_info).query_string);
       
   125 -	nsapi_free(SG(request_info).request_uri);
       
   126 -	nsapi_free((void*)(SG(request_info).request_method));
       
   127 -	nsapi_free(SG(request_info).path_translated);
       
   128 -	nsapi_free((void*)(SG(request_info).content_type));
       
   129 -
       
   130 -	FREE(request_context);
       
   131 +	pool_free(sn->pool, request_context);
       
   132  	SG(server_context) = NULL;
       
   133  
       
   134  	return retval;