|
|
f3124d |
Adapted for 5.4 from:
|
|
|
f3124d |
|
|
|
f3124d |
|
|
|
f3124d |
From 98b9dfaec95e6f910f125ed172cdbd25abd006ec Mon Sep 17 00:00:00 2001
|
|
|
f3124d |
From: Stanislav Malyshev <stas@php.net>
|
|
|
f3124d |
Date: Sun, 10 Jul 2016 16:17:54 -0700
|
|
|
f3124d |
Subject: [PATCH] Fix for HTTP_PROXY issue.
|
|
|
f3124d |
|
|
|
f3124d |
The following changes are made:
|
|
|
f3124d |
- _SERVER/_ENV only has HTTP_PROXY if the local environment has it,
|
|
|
f3124d |
and only one from the environment.
|
|
|
f3124d |
- getenv('HTTP_PROXY') only returns one from the local environment
|
|
|
f3124d |
- getenv has optional second parameter, telling it to only consider
|
|
|
f3124d |
local environment
|
|
|
f3124d |
---
|
|
|
f3124d |
UPGRADING | 3 +++
|
|
|
f3124d |
ext/standard/basic_functions.c | 17 +++++++------
|
|
|
f3124d |
main/SAPI.c | 48 +++++++++++++++++++-----------------
|
|
|
f3124d |
main/php_variables.c | 56 ++++++++++++++++++++++++++++--------------
|
|
|
f3124d |
4 files changed, 76 insertions(+), 48 deletions(-)
|
|
|
f3124d |
|
|
|
f3124d |
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
|
|
|
f3124d |
index 50b6bc7..8cbba14 100644
|
|
|
f3124d |
--- a/ext/standard/basic_functions.c
|
|
|
f3124d |
+++ b/ext/standard/basic_functions.c
|
|
|
f3124d |
@@ -3953,21 +3953,24 @@ PHP_FUNCTION(long2ip)
|
|
|
f3124d |
* System Functions *
|
|
|
f3124d |
********************/
|
|
|
f3124d |
|
|
|
f3124d |
-/* {{{ proto string getenv(string varname)
|
|
|
f3124d |
+/* {{{ proto string getenv(string varname[, bool local_only])
|
|
|
f3124d |
Get the value of an environment variable */
|
|
|
f3124d |
PHP_FUNCTION(getenv)
|
|
|
f3124d |
{
|
|
|
f3124d |
char *ptr, *str;
|
|
|
f3124d |
int str_len;
|
|
|
f3124d |
+ zend_bool local_only = 0;
|
|
|
f3124d |
|
|
|
f3124d |
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
|
|
|
f3124d |
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &str, &str_len, &local_only) == FAILURE) {
|
|
|
f3124d |
RETURN_FALSE;
|
|
|
f3124d |
}
|
|
|
f3124d |
|
|
|
f3124d |
- /* SAPI method returns an emalloc()'d string */
|
|
|
f3124d |
- ptr = sapi_getenv(str, str_len TSRMLS_CC);
|
|
|
f3124d |
- if (ptr) {
|
|
|
f3124d |
- RETURN_STRING(ptr, 0);
|
|
|
f3124d |
+ if (!local_only) {
|
|
|
f3124d |
+ /* SAPI method returns an emalloc()'d string */
|
|
|
f3124d |
+ ptr = sapi_getenv(str, str_len TSRMLS_CC);
|
|
|
f3124d |
+ if (ptr) {
|
|
|
f3124d |
+ RETURN_STRING(ptr, 0);
|
|
|
f3124d |
+ }
|
|
|
f3124d |
}
|
|
|
f3124d |
#ifdef PHP_WIN32
|
|
|
f3124d |
{
|
|
|
f3124d |
diff --git a/main/SAPI.c b/main/SAPI.c
|
|
|
f3124d |
index 0dd0b55..8a56c6d 100644
|
|
|
f3124d |
--- a/main/SAPI.c
|
|
|
f3124d |
+++ b/main/SAPI.c
|
|
|
f3124d |
@@ -1016,7 +1016,11 @@ SAPI_API struct stat *sapi_get_stat(TSRMLS_D)
|
|
|
f3124d |
|
|
|
f3124d |
SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC)
|
|
|
f3124d |
{
|
|
|
f3124d |
- if (sapi_module.getenv) {
|
|
|
f3124d |
+ if (!strncasecmp(name, "HTTP_PROXY", name_len)) {
|
|
|
f3124d |
+ /* Ugly fix for HTTP_PROXY issue */
|
|
|
f3124d |
+ return NULL;
|
|
|
f3124d |
+ }
|
|
|
f3124d |
+ if (sapi_module.getenv) {
|
|
|
f3124d |
char *value, *tmp = sapi_module.getenv(name, name_len TSRMLS_CC);
|
|
|
f3124d |
if (tmp) {
|
|
|
f3124d |
value = estrdup(tmp);
|
|
|
f3124d |
diff --git a/main/php_variables.c b/main/php_variables.c
|
|
|
f3124d |
index bf6b9f3..bbe57d3 100644
|
|
|
f3124d |
--- a/main/php_variables.c
|
|
|
f3124d |
+++ b/main/php_variables.c
|
|
|
f3124d |
@@ -735,10 +735,26 @@ static zend_bool php_auto_globals_create_files(const char *name, uint name_len T
|
|
|
f3124d |
|
|
|
f3124d |
zend_hash_update(&EG(symbol_table), name, name_len + 1, &vars, sizeof(zval *), NULL);
|
|
|
f3124d |
Z_ADDREF_P(vars);
|
|
|
f3124d |
-
|
|
|
f3124d |
+
|
|
|
f3124d |
return 0; /* don't rearm */
|
|
|
f3124d |
}
|
|
|
f3124d |
|
|
|
f3124d |
+/* Upgly hack to fix HTTP_PROXY issue */
|
|
|
f3124d |
+static void check_http_proxy(HashTable *var_table) {
|
|
|
f3124d |
+ if (zend_hash_exists(var_table, "HTTP_PROXY", sizeof("HTTP_PROXY"))) {
|
|
|
f3124d |
+ char *local_proxy = getenv("HTTP_PROXY");
|
|
|
f3124d |
+
|
|
|
f3124d |
+ if (!local_proxy) {
|
|
|
f3124d |
+ zend_hash_del(var_table, "HTTP_PROXY", sizeof("HTTP_PROXY"));
|
|
|
f3124d |
+ } else {
|
|
|
f3124d |
+ zval *local_zval;
|
|
|
f3124d |
+ ALLOC_INIT_ZVAL(local_zval);
|
|
|
f3124d |
+ ZVAL_STRING(local_zval, local_proxy, 1);
|
|
|
f3124d |
+ zend_hash_update(var_table, "HTTP_PROXY", sizeof("HTTP_PROXY"), &local_zval, sizeof(zval **), NULL);
|
|
|
f3124d |
+ }
|
|
|
f3124d |
+ }
|
|
|
f3124d |
+}
|
|
|
f3124d |
+
|
|
|
f3124d |
static zend_bool php_auto_globals_create_server(const char *name, uint name_len TSRMLS_DC)
|
|
|
f3124d |
{
|
|
|
f3124d |
if (PG(variables_order) && (strchr(PG(variables_order),'S') || strchr(PG(variables_order),'s'))) {
|
|
|
f3124d |
@@ -771,9 +787,10 @@ static zend_bool php_auto_globals_create_server(const char *name, uint name_len
|
|
|
f3124d |
PG(http_globals)[TRACK_VARS_SERVER] = server_vars;
|
|
|
f3124d |
}
|
|
|
f3124d |
|
|
|
f3124d |
+ check_http_proxy(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]));
|
|
|
f3124d |
zend_hash_update(&EG(symbol_table), name, name_len + 1, &PG(http_globals)[TRACK_VARS_SERVER], sizeof(zval *), NULL);
|
|
|
f3124d |
Z_ADDREF_P(PG(http_globals)[TRACK_VARS_SERVER]);
|
|
|
f3124d |
-
|
|
|
f3124d |
+
|
|
|
f3124d |
return 0; /* don't rearm */
|
|
|
f3124d |
}
|
|
|
f3124d |
|
|
|
f3124d |
@@ -787,11 +807,12 @@ static zend_bool php_auto_globals_create_env(const char *name, uint name_len TSR
|
|
|
f3124d |
zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_ENV]);
|
|
|
f3124d |
}
|
|
|
f3124d |
PG(http_globals)[TRACK_VARS_ENV] = env_vars;
|
|
|
f3124d |
-
|
|
|
f3124d |
+
|
|
|
f3124d |
if (PG(variables_order) && (strchr(PG(variables_order),'E') || strchr(PG(variables_order),'e'))) {
|
|
|
f3124d |
php_import_environment_variables(PG(http_globals)[TRACK_VARS_ENV] TSRMLS_CC);
|
|
|
f3124d |
}
|
|
|
f3124d |
|
|
|
f3124d |
+ check_http_proxy(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV]));
|
|
|
f3124d |
zend_hash_update(&EG(symbol_table), name, name_len + 1, &PG(http_globals)[TRACK_VARS_ENV], sizeof(zval *), NULL);
|
|
|
f3124d |
Z_ADDREF_P(PG(http_globals)[TRACK_VARS_ENV]);
|
|
|
f3124d |
|
|
|
f3124d |
--
|
|
|
f3124d |
2.1.4
|
|
|
f3124d |
|