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