Skip to content

Commit 98b9dfa

Browse files
committed
Fix for HTTP_PROXY issue.
The following changes are made: - _SERVER/_ENV only has HTTP_PROXY if the local environment has it, and only one from the environment. - getenv('HTTP_PROXY') only returns one from the local environment - getenv has optional second parameter, telling it to only consider local environment
1 parent b63d41e commit 98b9dfa

File tree

4 files changed

+76
-48
lines changed

4 files changed

+76
-48
lines changed

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ PHP 5.5 UPGRADE NOTES
194194
- Since 5.5.4, fputcsv() has fifth parameter escape_char, allowing to
195195
specify escape char.
196196

197+
- Since 5.5.38, getenv() has optional second parameter, making it only
198+
consider local environment and not SAPI environment if true.
199+
197200
4a. unserialize() change
198201
------------------------
199202

ext/standard/basic_functions.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,7 +3544,7 @@ PHPAPI double php_get_inf(void) /* {{{ */
35443544

35453545
#define BASIC_ADD_SUBMODULE(module) \
35463546
zend_hash_add_empty_element(&basic_submodules, #module, strlen(#module));
3547-
3547+
35483548
#define BASIC_RINIT_SUBMODULE(module) \
35493549
if (zend_hash_exists(&basic_submodules, #module, strlen(#module))) { \
35503550
PHP_RINIT(module)(INIT_FUNC_ARGS_PASSTHRU); \
@@ -4013,21 +4013,24 @@ PHP_FUNCTION(long2ip)
40134013
* System Functions *
40144014
********************/
40154015
4016-
/* {{{ proto string getenv(string varname)
4016+
/* {{{ proto string getenv(string varname[, bool local_only])
40174017
Get the value of an environment variable */
40184018
PHP_FUNCTION(getenv)
40194019
{
40204020
char *ptr, *str;
40214021
int str_len;
4022+
zend_bool local_only = 0;
40224023
4023-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
4024+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &str, &str_len, &local_only) == FAILURE) {
40244025
RETURN_FALSE;
40254026
}
40264027
4027-
/* SAPI method returns an emalloc()'d string */
4028-
ptr = sapi_getenv(str, str_len TSRMLS_CC);
4029-
if (ptr) {
4030-
RETURN_STRING(ptr, 0);
4028+
if (!local_only) {
4029+
/* SAPI method returns an emalloc()'d string */
4030+
ptr = sapi_getenv(str, str_len TSRMLS_CC);
4031+
if (ptr) {
4032+
RETURN_STRING(ptr, 0);
4033+
}
40314034
}
40324035
#ifdef PHP_WIN32
40334036
{

main/SAPI.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
+----------------------------------------------------------------------+
33
| PHP Version 5 |
44
+----------------------------------------------------------------------+
@@ -132,7 +132,7 @@ PHP_FUNCTION(header_register_callback)
132132
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &callback_func) == FAILURE) {
133133
return;
134134
}
135-
135+
136136
if (!zend_is_callable(callback_func, 0, &callback_name TSRMLS_CC)) {
137137
efree(callback_name);
138138
RETURN_FALSE;
@@ -160,10 +160,10 @@ static void sapi_run_header_callback(TSRMLS_D)
160160
char *callback_name = NULL;
161161
char *callback_error = NULL;
162162
zval *retval_ptr = NULL;
163-
163+
164164
if (zend_fcall_info_init(SG(callback_func), 0, &fci, &SG(fci_cache), &callback_name, &callback_error TSRMLS_CC) == SUCCESS) {
165165
fci.retval_ptr_ptr = &retval_ptr;
166-
166+
167167
error = zend_call_function(&fci, &SG(fci_cache) TSRMLS_CC);
168168
if (error == FAILURE) {
169169
goto callback_failed;
@@ -174,13 +174,13 @@ static void sapi_run_header_callback(TSRMLS_D)
174174
callback_failed:
175175
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the sapi_header_callback");
176176
}
177-
177+
178178
if (callback_name) {
179179
efree(callback_name);
180180
}
181181
if (callback_error) {
182182
efree(callback_error);
183-
}
183+
}
184184
}
185185

186186
SAPI_API void sapi_handle_post(void *arg TSRMLS_DC)
@@ -386,11 +386,11 @@ SAPI_API void sapi_activate_headers_only(TSRMLS_D)
386386
if (SG(request_info).headers_read == 1)
387387
return;
388388
SG(request_info).headers_read = 1;
389-
zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct),
389+
zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct),
390390
(void (*)(void *)) sapi_free_header, 0);
391391
SG(sapi_headers).send_default_content_type = 1;
392392

393-
/* SG(sapi_headers).http_response_code = 200; */
393+
/* SG(sapi_headers).http_response_code = 200; */
394394
SG(sapi_headers).http_status_line = NULL;
395395
SG(sapi_headers).mimetype = NULL;
396396
SG(read_post_bytes) = 0;
@@ -403,7 +403,7 @@ SAPI_API void sapi_activate_headers_only(TSRMLS_D)
403403
SG(global_request_time) = 0;
404404

405405
/*
406-
* It's possible to override this general case in the activate() callback,
406+
* It's possible to override this general case in the activate() callback,
407407
* if necessary.
408408
*/
409409
if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
@@ -465,8 +465,8 @@ SAPI_API void sapi_activate(TSRMLS_D)
465465
* depending on given content type */
466466
sapi_read_post_data(TSRMLS_C);
467467
} else {
468-
/* Any other method with content payload will fill $HTTP_RAW_POST_DATA
469-
* if it is enabled by always_populate_raw_post_data.
468+
/* Any other method with content payload will fill $HTTP_RAW_POST_DATA
469+
* if it is enabled by always_populate_raw_post_data.
470470
* It's up to the webserver to decide whether to allow a method or not. */
471471
SG(request_info).content_type_dup = NULL;
472472
if (sapi_module.default_post_reader) {
@@ -497,14 +497,14 @@ static void sapi_send_headers_free(TSRMLS_D)
497497
SG(sapi_headers).http_status_line = NULL;
498498
}
499499
}
500-
500+
501501
SAPI_API void sapi_deactivate(TSRMLS_D)
502502
{
503503
zend_llist_destroy(&SG(sapi_headers).headers);
504504
if (SG(request_info).post_data) {
505505
efree(SG(request_info).post_data);
506506
} else if (SG(server_context)) {
507-
if(sapi_module.read_post) {
507+
if(sapi_module.read_post) {
508508
/* make sure we've consumed all request input data */
509509
char dummy[SAPI_POST_BLOCK_SIZE];
510510
int read_bytes;
@@ -516,7 +516,7 @@ SAPI_API void sapi_deactivate(TSRMLS_D)
516516
}
517517
if (SG(request_info).raw_post_data) {
518518
efree(SG(request_info).raw_post_data);
519-
}
519+
}
520520
if (SG(request_info).auth_user) {
521521
efree(SG(request_info).auth_user);
522522
}
@@ -574,7 +574,7 @@ static int sapi_extract_response_code(const char *header_line)
574574
break;
575575
}
576576
}
577-
577+
578578
return code;
579579
}
580580

@@ -594,7 +594,7 @@ static void sapi_update_response_code(int ncode TSRMLS_DC)
594594
SG(sapi_headers).http_response_code = ncode;
595595
}
596596

597-
/*
597+
/*
598598
* since zend_llist_del_element only remove one matched item once,
599599
* we should remove them by ourself
600600
*/
@@ -630,7 +630,7 @@ SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bo
630630
{
631631
sapi_header_line ctr = {0};
632632
int r;
633-
633+
634634
ctr.line = header_line;
635635
ctr.line_len = header_line_len;
636636

@@ -724,7 +724,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
724724
} while(header_line_len && isspace(header_line[header_line_len-1]));
725725
header_line[header_line_len]='\0';
726726
}
727-
727+
728728
if (op == SAPI_HEADER_DELETE) {
729729
if (strchr(header_line, ':')) {
730730
efree(header_line);
@@ -762,7 +762,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
762762
sapi_header.header_len = header_line_len;
763763

764764
/* Check the header for a few cases that we have special support for in SAPI */
765-
if (header_line_len>=5
765+
if (header_line_len>=5
766766
&& !strncasecmp(header_line, "HTTP/", 5)) {
767767
/* filter out the response code */
768768
sapi_update_response_code(sapi_extract_response_code(header_line) TSRMLS_CC);
@@ -821,8 +821,8 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
821821
/* Return a Found Redirect if one is not already specified */
822822
if (http_response_code) { /* user specified redirect code */
823823
sapi_update_response_code(http_response_code TSRMLS_CC);
824-
} else if (SG(request_info).proto_num > 1000 &&
825-
SG(request_info).request_method &&
824+
} else if (SG(request_info).proto_num > 1000 &&
825+
SG(request_info).request_method &&
826826
strcmp(SG(request_info).request_method, "HEAD") &&
827827
strcmp(SG(request_info).request_method, "GET")) {
828828
sapi_update_response_code(303 TSRMLS_CC);
@@ -1011,7 +1011,11 @@ SAPI_API struct stat *sapi_get_stat(TSRMLS_D)
10111011

10121012
SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC)
10131013
{
1014-
if (sapi_module.getenv) {
1014+
if (!strncasecmp(name, "HTTP_PROXY", name_len)) {
1015+
/* Ugly fix for HTTP_PROXY issue */
1016+
return NULL;
1017+
}
1018+
if (sapi_module.getenv) {
10151019
char *value, *tmp = sapi_module.getenv(name, name_len TSRMLS_CC);
10161020
if (tmp) {
10171021
value = estrdup(tmp);

0 commit comments

Comments
 (0)