- http_get_request_headers() modified $_SERVER array keys
authorMichael Wallner <mike@php.net>
Wed, 9 Nov 2005 15:24:05 +0000 (15:24 +0000)
committerMichael Wallner <mike@php.net>
Wed, 9 Nov 2005 15:24:05 +0000 (15:24 +0000)
http_headers_api.c
package2.xml
php_http_std_defs.h

index 0be9b2c018c763b2a6ad002d780ba64ce696174a..b61646d34c4ac84cd7965d651fe6149f49fe8393 100644 (file)
@@ -433,24 +433,38 @@ PHP_HTTP_API void _http_get_request_headers_ex(HashTable *headers, zend_bool pre
 {
        char *key = NULL;
        ulong idx = 0;
 {
        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)) {
        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;
        
                                key += 5;
+                               keylen -= 6;
                                if (prettify) {
                                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);
                                }
        
                                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);
                                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;
                                key = NULL;
+                               keylen = 0;
                        }
                }
        }
                        }
                }
        }
index 5b2e9508060d27993f89ebdeae091ccbabb845e0..6dd18271cdaaa0baa89cf12fe5165b0414b6e576 100644 (file)
@@ -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
 + 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
 ]]></notes>
  <contents>
   <dir name="/">
 ]]></notes>
  <contents>
   <dir name="/">
index 558a8ec8d5b53a6fe0e2c02e28d29597ad08fb76..489e37283ee3b2831b967c34e073766f54d9bbb9 100644 (file)
@@ -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)) \
 
                        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); \
 #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); \