-
-
Save smalyshev/ba40554d812723e0397dd0cfef57932d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 98b9dfaec95e6f910f125ed172cdbd25abd006ec | |
Author: Stanislav Malyshev <stas@php.net> | |
Date: Sun Jul 10 16:17:54 2016 -0700 | |
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 | |
diff --git a/UPGRADING b/UPGRADING | |
index 7b51ae5..84a925a 100644 | |
--- a/UPGRADING | |
+++ b/UPGRADING | |
@@ -194,6 +194,9 @@ PHP 5.5 UPGRADE NOTES | |
- Since 5.5.4, fputcsv() has fifth parameter escape_char, allowing to | |
specify escape char. | |
+- Since 5.5.38, getenv() has optional second parameter, making it only | |
+ consider local environment and not SAPI environment if true. | |
+ | |
4a. unserialize() change | |
------------------------ | |
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c | |
index 50b6bc7..8cbba14 100644 | |
--- a/ext/standard/basic_functions.c | |
+++ b/ext/standard/basic_functions.c | |
@@ -4013,22 +4013,25 @@ PHP_FUNCTION(long2ip) | |
* System Functions * | |
********************/ | |
-/* {{{ proto string getenv(string varname) | |
+/* {{{ proto string getenv(string varname[, bool local_only]) | |
Get the value of an environment variable */ | |
PHP_FUNCTION(getenv) | |
{ | |
char *ptr, *str; | |
int str_len; | |
+ zend_bool local_only = 0; | |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { | |
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &str, &str_len, &local_only) == FAILURE) { | |
RETURN_FALSE; | |
} | |
+ if (!local_only) { | |
/* SAPI method returns an emalloc()'d string */ | |
ptr = sapi_getenv(str, str_len TSRMLS_CC); | |
if (ptr) { | |
RETURN_STRING(ptr, 0); | |
} | |
+ } | |
#ifdef PHP_WIN32 | |
{ | |
char dummybuf; | |
diff --git a/main/SAPI.c b/main/SAPI.c | |
index 0dd0b55..8a56c6d 100644 | |
--- a/main/SAPI.c | |
+++ b/main/SAPI.c | |
@@ -1011,6 +1011,10 @@ SAPI_API struct stat *sapi_get_stat(TSRMLS_D) | |
SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC) | |
{ | |
+ if (!strncasecmp(name, "HTTP_PROXY", name_len)) { | |
+ /* Ugly fix for HTTP_PROXY issue */ | |
+ return NULL; | |
+ } | |
if (sapi_module.getenv) { | |
char *value, *tmp = sapi_module.getenv(name, name_len TSRMLS_CC); | |
if (tmp) { | |
diff --git a/main/php_variables.c b/main/php_variables.c | |
index bf6b9f3..bbe57d3 100644 | |
--- a/main/php_variables.c | |
+++ b/main/php_variables.c | |
@@ -722,6 +722,22 @@ static zend_bool php_auto_globals_create_files(const char *name, uint name_len T | |
return 0; /* don't rearm */ | |
} | |
+/* Upgly hack to fix HTTP_PROXY issue */ | |
+static void check_http_proxy(HashTable *var_table) { | |
+ if (zend_hash_exists(var_table, "HTTP_PROXY", sizeof("HTTP_PROXY"))) { | |
+ char *local_proxy = getenv("HTTP_PROXY"); | |
+ | |
+ if (!local_proxy) { | |
+ zend_hash_del(var_table, "HTTP_PROXY", sizeof("HTTP_PROXY")); | |
+ } else { | |
+ zval *local_zval; | |
+ ALLOC_INIT_ZVAL(local_zval); | |
+ ZVAL_STRING(local_zval, local_proxy, 1); | |
+ zend_hash_update(var_table, "HTTP_PROXY", sizeof("HTTP_PROXY"), &local_zval, sizeof(zval **), NULL); | |
+ } | |
+ } | |
+} | |
+ | |
static zend_bool php_auto_globals_create_server(const char *name, uint name_len TSRMLS_DC) | |
{ | |
if (PG(variables_order) && (strchr(PG(variables_order),'S') || strchr(PG(variables_order),'s'))) { | |
@@ -754,6 +770,7 @@ static zend_bool php_auto_globals_create_server(const char *name, uint name_len | |
PG(http_globals)[TRACK_VARS_SERVER] = server_vars; | |
} | |
+ check_http_proxy(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])); | |
zend_hash_update(&EG(symbol_table), name, name_len + 1, &PG(http_globals)[TRACK_VARS_SERVER], sizeof(zval *), NULL); | |
Z_ADDREF_P(PG(http_globals)[TRACK_VARS_SERVER]); | |
@@ -775,6 +792,7 @@ static zend_bool php_auto_globals_create_env(const char *name, uint name_len TSR | |
php_import_environment_variables(PG(http_globals)[TRACK_VARS_ENV] TSRMLS_CC); | |
} | |
+ check_http_proxy(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])); | |
zend_hash_update(&EG(symbol_table), name, name_len + 1, &PG(http_globals)[TRACK_VARS_ENV], sizeof(zval *), NULL); | |
Z_ADDREF_P(PG(http_globals)[TRACK_VARS_ENV]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment