From 64f9c50ce4d7f7ecc5b414b46fe44c28bf54974d Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 9 Nov 2005 15:24:05 +0000 Subject: [PATCH] - http_get_request_headers() modified $_SERVER array keys --- http_headers_api.c | 22 ++++++++++++++++++---- package2.xml | 1 + php_http_std_defs.h | 6 ++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/http_headers_api.c b/http_headers_api.c index 0be9b2c..b61646d 100644 --- a/http_headers_api.c +++ b/http_headers_api.c @@ -433,24 +433,38 @@ PHP_HTTP_API void _http_get_request_headers_ex(HashTable *headers, zend_bool pre { char *key = NULL; ulong idx = 0; + uint keylen = 0; zval array, **hsv; HashPosition pos; Z_ARRVAL(array) = headers; if (SUCCESS == zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &hsv)) { - FOREACH_KEY(pos, *hsv, key, idx) { - if (key && !strncmp(key, "HTTP_", 5)) { - zval **header; + FOREACH_KEYLEN(pos, *hsv, key, keylen, idx) { + if (key && keylen > 6 && !strncmp(key, "HTTP_", 5)) { + zval **header, *orig; key += 5; + keylen -= 6; if (prettify) { - key = pretty_key(key, strlen(key), 1, 1); + key = pretty_key(estrndup(key, keylen), keylen, 1, 1); } zend_hash_get_current_data_ex(Z_ARRVAL_PP(hsv), (void **) &header, &pos); + + orig = *header; + convert_to_string_ex(header); add_assoc_stringl(&array, key, Z_STRVAL_PP(header), Z_STRLEN_PP(header), 1); + if (orig != *header) { + zval_ptr_dtor(header); + } + + if (prettify) { + efree(key); + } + key = NULL; + keylen = 0; } } } diff --git a/package2.xml b/package2.xml index 5b2e950..6dd1827 100644 --- a/package2.xml +++ b/package2.xml @@ -45,6 +45,7 @@ + Class HttpMessage implements Serializable if PHP >= 5.1 is available * Fixed a bug that caused a warning about an invalid curl handle at HttpRequestPool destruction +* Fixed a bug with http_get_request_headers() modifying $_SERVER array ]]> diff --git a/php_http_std_defs.h b/php_http_std_defs.h index 558a8ec..489e372 100644 --- a/php_http_std_defs.h +++ b/php_http_std_defs.h @@ -141,6 +141,12 @@ typedef int STATUS; zend_hash_get_current_key_ex(hash, &strkey, NULL, &numkey, 0, &pos) != HASH_KEY_NON_EXISTANT; \ zend_hash_move_forward_ex(hash, &pos)) \ +#define FOREACH_KEYLEN(pos, array, strkey, keylen, numkey) FOREACH_HASH_KEYLEN(pos, Z_ARRVAL_P(array), strkey, keylen, numkey) +#define FOREACH_HASH_KEYLEN(pos, hash, strkey, keylen, numkey) \ + for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \ + zend_hash_get_current_key_ex(hash, &strkey, &keylen, &numkey, 0, &pos) != HASH_KEY_NON_EXISTANT; \ + zend_hash_move_forward_ex(hash, &pos)) \ + #define FOREACH_KEYVAL(pos, array, strkey, numkey, val) FOREACH_HASH_KEYVAL(pos, Z_ARRVAL_P(array), strkey, numkey, val) #define FOREACH_HASH_KEYVAL(pos, hash, strkey, numkey, val) \ for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \ -- 2.30.2