Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 849 lines (748 sloc) 24.469 kb
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
1 /*
2 +----------------------------------------------------------------------+
dbeb415 @andigutmans - A belated happy holidays and PHP 5
andigutmans authored
3 | PHP Version 5 |
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
4 +----------------------------------------------------------------------+
8775a37 @felipensp - Year++
felipensp authored
5 | Copyright (c) 1997-2012 The PHP Group |
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
6 +----------------------------------------------------------------------+
5bd9322 bump year and license version
foobar authored
7 | This source file is subject to version 3.01 of the PHP license, |
c5724cb @zsuraski License update
zsuraski authored
8 | that is bundled with this package in the file LICENSE, and is |
f68c7ff updating license information in the headers.
James Cox authored
9 | available through the world-wide-web at the following url: |
5bd9322 bump year and license version
foobar authored
10 | http://www.php.net/license/3_01.txt |
c5724cb @zsuraski License update
zsuraski authored
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
14 +----------------------------------------------------------------------+
15 | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
15fee4d @zsuraski - Seriously optimize and clean php_parse_gpc_data()
zsuraski authored
16 | Zeev Suraski <zeev@zend.com> |
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
17 +----------------------------------------------------------------------+
18 */
8e3f23e ws fixes + missing $Id$ tags, headers added
foobar authored
19
349b2be fixed typo in CVS id
foobar authored
20 /* $Id$ */
6f7c0ed @zsuraski Remove tls.[ch]
zsuraski authored
21
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
22 #include <stdio.h>
23 #include "php.h"
fc67810 @zsuraski post.c really had nothing to do with POST anymore, and it belongs to the...
zsuraski authored
24 #include "ext/standard/php_standard.h"
66c05f7 Fixed compiler warnings.
Ilia Alshanetsky authored
25 #include "ext/standard/credits.h"
9ab35ae @zsuraski Tried to centralize global variable registration as much as possible:
zsuraski authored
26 #include "php_variables.h"
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
27 #include "php_globals.h"
8e0ae5d Cleaning up some mess
Sascha Schumann authored
28 #include "php_content_types.h"
3cd0af1 @zsuraski * Get the Apache module to compile again
zsuraski authored
29 #include "SAPI.h"
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
30 #include "zend_globals.h"
31
96b9c0a make php_import_environment_variables overwritable so fastcgi can correc...
Shane Caraveo authored
32 /* for systems that need to override reading of environment variables */
33 void _php_import_environment_variables(zval *array_ptr TSRMLS_DC);
34 PHPAPI void (*php_import_environment_variables)(zval *array_ptr TSRMLS_DC) = _php_import_environment_variables;
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
35
d87cc97 @zsuraski Redesigned thread safety mechanism - nua nua
zsuraski authored
36 PHPAPI void php_register_variable(char *var, char *strval, zval *track_vars_array TSRMLS_DC)
fe6f871 @zsuraski - Get rid of ELS_*(), and use TSRMLS_*() instead.
zsuraski authored
37 {
d87cc97 @zsuraski Redesigned thread safety mechanism - nua nua
zsuraski authored
38 php_register_variable_safe(var, strval, strlen(strval), track_vars_array TSRMLS_CC);
0731f54 @smalyshev Fix #7987: POST/GET: string with \0(%00) values not parsed correctly
smalyshev authored
39 }
40
41 /* binary-safe version */
d87cc97 @zsuraski Redesigned thread safety mechanism - nua nua
zsuraski authored
42 PHPAPI void php_register_variable_safe(char *var, char *strval, int str_len, zval *track_vars_array TSRMLS_DC)
739bdec @zsuraski Worked on beautifying rfc1867.c a bit
zsuraski authored
43 {
44 zval new_entry;
6ad0dbf Add some assertion
Yasuo Ohgaki authored
45 assert(strval != NULL);
46
739bdec @zsuraski Worked on beautifying rfc1867.c a bit
zsuraski authored
47 /* Prepare value */
c033288 Back-substitute for Z_* macro's. If it breaks some extension (the script...
Jeroen van Wolffelaar authored
48 Z_STRLEN(new_entry) = str_len;
cc1c7af @pierrejoye - remove magic quotes support, functions are kept (see the NEWS entry fo...
pierrejoye authored
49 Z_STRVAL(new_entry) = estrndup(strval, Z_STRLEN(new_entry));
c033288 Back-substitute for Z_* macro's. If it breaks some extension (the script...
Jeroen van Wolffelaar authored
50 Z_TYPE(new_entry) = IS_STRING;
739bdec @zsuraski Worked on beautifying rfc1867.c a bit
zsuraski authored
51
d87cc97 @zsuraski Redesigned thread safety mechanism - nua nua
zsuraski authored
52 php_register_variable_ex(var, &new_entry, track_vars_array TSRMLS_CC);
739bdec @zsuraski Worked on beautifying rfc1867.c a bit
zsuraski authored
53 }
54
f52d71d @rlerdorf Fix for bugs 13961, 39927 and 45947
rlerdorf authored
55 PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars_array TSRMLS_DC)
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
56 {
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
57 char *p = NULL;
58 char *ip; /* index pointer */
29a909e Fixed memory leaks
Dmitry Stogov authored
59 char *index;
f52d71d @rlerdorf Fix for bugs 13961, 39927 and 45947
rlerdorf authored
60 char *var, *var_orig;
739bdec @zsuraski Worked on beautifying rfc1867.c a bit
zsuraski authored
61 int var_len, index_len;
93a5238 Fixed bug #24007 (Problem with register_globals & arrays)
Ilia Alshanetsky authored
62 zval *gpc_element, **gpc_element_p;
e9d452b Optimization
Dmitry Stogov authored
63 zend_bool is_array = 0;
e642d18 ws, pval -> zval
foobar authored
64 HashTable *symtable1 = NULL;
ab6ce92 Use stack instead of heap
Dmitry Stogov authored
65 ALLOCA_FLAG(use_heap)
eb32144 @zsuraski - Remove track_vars - it is now always on
zsuraski authored
66
5f17800 @rlerdorf Oops, fix the assert.
rlerdorf authored
67 assert(var_name != NULL);
322d57f @tony2001 WS
tony2001 authored
68
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
69 if (track_vars_array) {
683251e Fixed bug #20796. $_GET/$_POST/$_COOKIE data can get overwritten when
Ilia Alshanetsky authored
70 symtable1 = Z_ARRVAL_P(track_vars_array);
71 }
febee11 @KalleZ Removed register_globals
KalleZ authored
72
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
73 if (!symtable1) {
eb32144 @zsuraski - Remove track_vars - it is now always on
zsuraski authored
74 /* Nothing to do */
739bdec @zsuraski Worked on beautifying rfc1867.c a bit
zsuraski authored
75 zval_dtor(val);
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
76 return;
77 }
78
e9d452b Optimization
Dmitry Stogov authored
79
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
80 /* ignore leading spaces in the variable name */
ab6ce92 Use stack instead of heap
Dmitry Stogov authored
81 while (*var_name && *var_name==' ') {
82 var_name++;
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
83 }
ab6ce92 Use stack instead of heap
Dmitry Stogov authored
84
85 /*
86 * Prepare variable name
87 */
88 var_len = strlen(var_name);
89 var = var_orig = do_alloca(var_len + 1, use_heap);
90 memcpy(var_orig, var_name, var_len + 1);
e9d452b Optimization
Dmitry Stogov authored
91
92 /* ensure that we don't have spaces or dots in the variable name (not binary safe) */
93 for (p = var; *p; p++) {
94 if (*p == ' ' || *p == '.') {
95 *p='_';
96 } else if (*p == '[') {
97 is_array = 1;
98 ip = p;
99 *p = 0;
100 break;
101 }
102 }
103 var_len = p - var;
104
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
105 if (var_len==0) { /* empty variable name, or variable name with a space in it */
739bdec @zsuraski Worked on beautifying rfc1867.c a bit
zsuraski authored
106 zval_dtor(val);
ab6ce92 Use stack instead of heap
Dmitry Stogov authored
107 free_alloca(var_orig, use_heap);
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
108 return;
109 }
1a04335 MFH: Fixed possible GLOBALS variable override when register_globals are ...
Ilia Alshanetsky authored
110
111 /* GLOBALS hijack attempt, reject parameter */
e9d452b Optimization
Dmitry Stogov authored
112 if (symtable1 == EG(active_symbol_table) &&
113 var_len == sizeof("GLOBALS")-1 &&
114 !memcmp(var, "GLOBALS", sizeof("GLOBALS")-1)) {
1a04335 MFH: Fixed possible GLOBALS variable override when register_globals are ...
Ilia Alshanetsky authored
115 zval_dtor(val);
ab6ce92 Use stack instead of heap
Dmitry Stogov authored
116 free_alloca(var_orig, use_heap);
1a04335 MFH: Fixed possible GLOBALS variable override when register_globals are ...
Ilia Alshanetsky authored
117 return;
118 }
119
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
120 index = var;
121 index_len = var_len;
122
e9d452b Optimization
Dmitry Stogov authored
123 if (is_array) {
32fb34e @smalyshev limit nesting level of input variables
smalyshev authored
124 int nest_level = 0;
e9d452b Optimization
Dmitry Stogov authored
125 while (1) {
ba8cfb4 @rlerdorf Minor consistency cleanup
rlerdorf authored
126 char *index_s;
1f50681 Fixed bug #21149 (fixed handling of unterminated '[').
Ilia Alshanetsky authored
127 int new_idx_len = 0;
128
a0215e9 @smalyshev fix variable name
smalyshev authored
129 if(++nest_level > PG(max_input_nesting_level)) {
a8be5f4 Improved fix for MOPB-02-2007
Ilia Alshanetsky authored
130 HashTable *ht;
32fb34e @smalyshev limit nesting level of input variables
smalyshev authored
131 /* too many levels of nesting */
a8be5f4 Improved fix for MOPB-02-2007
Ilia Alshanetsky authored
132
133 if (track_vars_array) {
134 ht = Z_ARRVAL_P(track_vars_array);
6672171 @laruence Fixed bug #61000 (Exceeding max nesting level doesn't delete numerical v...
laruence authored
135 zend_symtable_del(ht, var, var_len + 1);
a8be5f4 Improved fix for MOPB-02-2007
Ilia Alshanetsky authored
136 }
137
138 zval_dtor(val);
139
521917b @tony2001 MFH
tony2001 authored
140 /* do not output the error message to the screen,
141 this helps us to to avoid "information disclosure" */
a8be5f4 Improved fix for MOPB-02-2007
Ilia Alshanetsky authored
142 if (!PG(display_errors)) {
f26145f MFH:- Improved the error message for exceeding max_input_nesting_level.
foobar authored
143 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variable nesting level exceeded %ld. To increase the limit change max_input_nesting_level in php.ini.", PG(max_input_nesting_level));
a8be5f4 Improved fix for MOPB-02-2007
Ilia Alshanetsky authored
144 }
ab6ce92 Use stack instead of heap
Dmitry Stogov authored
145 free_alloca(var_orig, use_heap);
a8be5f4 Improved fix for MOPB-02-2007
Ilia Alshanetsky authored
146 return;
32fb34e @smalyshev limit nesting level of input variables
smalyshev authored
147 }
148
1f50681 Fixed bug #21149 (fixed handling of unterminated '[').
Ilia Alshanetsky authored
149 ip++;
150 index_s = ip;
151 if (isspace(*ip)) {
152 ip++;
153 }
154 if (*ip==']') {
155 index_s = NULL;
156 } else {
157 ip = strchr(ip, ']');
158 if (!ip) {
159 /* PHP variables cannot contain '[' in their names, so we replace the character with a '_' */
160 *(index_s - 1) = '_';
e865bc2 @tony2001 fix bug #30442 ( segmentation fault when parsing ?getvariable[][ )
tony2001 authored
161
a8be5f4 Improved fix for MOPB-02-2007
Ilia Alshanetsky authored
162 index_len = 0;
e865bc2 @tony2001 fix bug #30442 ( segmentation fault when parsing ?getvariable[][ )
tony2001 authored
163 if (index) {
a8be5f4 Improved fix for MOPB-02-2007
Ilia Alshanetsky authored
164 index_len = strlen(index);
e865bc2 @tony2001 fix bug #30442 ( segmentation fault when parsing ?getvariable[][ )
tony2001 authored
165 }
1f50681 Fixed bug #21149 (fixed handling of unterminated '[').
Ilia Alshanetsky authored
166 goto plain_var;
167 return;
168 }
169 *ip = 0;
170 new_idx_len = strlen(index_s);
171 }
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
172
173 if (!index) {
174 MAKE_STD_ZVAL(gpc_element);
175 array_init(gpc_element);
29a909e Fixed memory leaks
Dmitry Stogov authored
176 if (zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p) == FAILURE) {
177 zval_ptr_dtor(&gpc_element);
178 zval_dtor(val);
179 free_alloca(var_orig, use_heap);
180 return;
181 }
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
182 } else {
29a909e Fixed memory leaks
Dmitry Stogov authored
183 if (zend_symtable_find(symtable1, index, index_len + 1, (void **) &gpc_element_p) == FAILURE
c033288 Back-substitute for Z_* macro's. If it breaks some extension (the script...
Jeroen van Wolffelaar authored
184 || Z_TYPE_PP(gpc_element_p) != IS_ARRAY) {
2ad7f44 Improved max_input_vars directive to check nested variables
Dmitry Stogov authored
185 MAKE_STD_ZVAL(gpc_element);
186 array_init(gpc_element);
187 zend_symtable_update(symtable1, index, index_len + 1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
188 }
189 }
c033288 Back-substitute for Z_* macro's. If it breaks some extension (the script...
Jeroen van Wolffelaar authored
190 symtable1 = Z_ARRVAL_PP(gpc_element_p);
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
191 /* ip pointed to the '[' character, now obtain the key */
1f50681 Fixed bug #21149 (fixed handling of unterminated '[').
Ilia Alshanetsky authored
192 index = index_s;
193 index_len = new_idx_len;
194
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
195 ip++;
e642d18 ws, pval -> zval
foobar authored
196 if (*ip == '[') {
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
197 is_array = 1;
198 *ip = 0;
199 } else {
efad378 Fixed bug #37276 (problems witch $_POST array)
Dmitry Stogov authored
200 goto plain_var;
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
201 }
e9d452b Optimization
Dmitry Stogov authored
202 }
203 } else {
1f50681 Fixed bug #21149 (fixed handling of unterminated '[').
Ilia Alshanetsky authored
204 plain_var:
e9d452b Optimization
Dmitry Stogov authored
205 MAKE_STD_ZVAL(gpc_element);
206 gpc_element->value = val->value;
207 Z_TYPE_P(gpc_element) = Z_TYPE_P(val);
208 if (!index) {
29a909e Fixed memory leaks
Dmitry Stogov authored
209 if (zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p) == FAILURE) {
210 zval_ptr_dtor(&gpc_element);
211 }
e9d452b Optimization
Dmitry Stogov authored
212 } else {
213 /*
214 * According to rfc2965, more specific paths are listed above the less specific ones.
215 * If we encounter a duplicate cookie name, we should skip it, since it is not possible
216 * to have the same (plain text) cookie name for the same path and we should not overwrite
217 * more specific cookies with the less specific ones.
218 */
219 if (PG(http_globals)[TRACK_VARS_COOKIE] &&
220 symtable1 == Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]) &&
29a909e Fixed memory leaks
Dmitry Stogov authored
221 zend_symtable_exists(symtable1, index, index_len + 1)) {
e9d452b Optimization
Dmitry Stogov authored
222 zval_ptr_dtor(&gpc_element);
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
223 } else {
2ad7f44 Improved max_input_vars directive to check nested variables
Dmitry Stogov authored
224 zend_symtable_update(symtable1, index, index_len + 1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
225 }
226 }
227 }
ab6ce92 Use stack instead of heap
Dmitry Stogov authored
228 free_alloca(var_orig, use_heap);
b2c0acb @zsuraski - Rewrote the GET/POST/Cookie data reader to support multi-dimensional
zsuraski authored
229 }
230
0dab84d fix SAPI_POST_* exports
Daniel Beulshausen authored
231 SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler)
a6393de @zsuraski Make POST handling the way it should be. RFC1867, and any future POST h...
zsuraski authored
232 {
7ba86d0 Fixed bug #38236 (Binary data gets corrupted on multipart/formdata POST)...
Ilia Alshanetsky authored
233 char *var, *val, *e, *s, *p;
a6393de @zsuraski Make POST handling the way it should be. RFC1867, and any future POST h...
zsuraski authored
234 zval *array_ptr = (zval *) arg;
2ad7f44 Improved max_input_vars directive to check nested variables
Dmitry Stogov authored
235 long count = 0;
a6393de @zsuraski Make POST handling the way it should be. RFC1867, and any future POST h...
zsuraski authored
236
e642d18 ws, pval -> zval
foobar authored
237 if (SG(request_info).post_data == NULL) {
5b3ee5f break out if there is no data to work on.
Stefan Esser authored
238 return;
239 }
240
7ba86d0 Fixed bug #38236 (Binary data gets corrupted on multipart/formdata POST)...
Ilia Alshanetsky authored
241 s = SG(request_info).post_data;
242 e = s + SG(request_info).post_data_length;
a6393de @zsuraski Make POST handling the way it should be. RFC1867, and any future POST h...
zsuraski authored
243
7ba86d0 Fixed bug #38236 (Binary data gets corrupted on multipart/formdata POST)...
Ilia Alshanetsky authored
244 while (s < e && (p = memchr(s, '&', (e - s)))) {
245 last_value:
246 if ((val = memchr(s, '=', (p - s)))) { /* have a value */
750b033 - Fix sapi_input_filter patch. Returning 1 from the filter handler shoul...
Derick Rethans authored
247 unsigned int val_len, new_val_len;
0731f54 @smalyshev Fix #7987: POST/GET: string with \0(%00) values not parsed correctly
smalyshev authored
248
2ad7f44 Improved max_input_vars directive to check nested variables
Dmitry Stogov authored
249 if (++count > PG(max_input_vars)) {
250 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variables exceeded %ld. To increase the limit change max_input_vars in php.ini.", PG(max_input_vars));
251 return;
252 }
7ba86d0 Fixed bug #38236 (Binary data gets corrupted on multipart/formdata POST)...
Ilia Alshanetsky authored
253 var = s;
254
255 php_url_decode(var, (val - s));
256 val++;
257 val_len = php_url_decode(val, (p - val));
59d55ef As long we pass values by reference this is needed. Ugly!
Stefan Esser authored
258 val = estrndup(val, val_len);
750b033 - Fix sapi_input_filter patch. Returning 1 from the filter handler shoul...
Derick Rethans authored
259 if (sapi_module.input_filter(PARSE_POST, var, &val, val_len, &new_val_len TSRMLS_CC)) {
260 php_register_variable_safe(var, val, new_val_len, array_ptr TSRMLS_CC);
370dfd3 - Prevent registration of the variable when a zero-length is returned
Derick Rethans authored
261 }
59d55ef As long we pass values by reference this is needed. Ugly!
Stefan Esser authored
262 efree(val);
a6393de @zsuraski Make POST handling the way it should be. RFC1867, and any future POST h...
zsuraski authored
263 }
7ba86d0 Fixed bug #38236 (Binary data gets corrupted on multipart/formdata POST)...
Ilia Alshanetsky authored
264 s = p + 1;
265 }
266 if (s < e) {
267 p = e;
268 goto last_value;
a6393de @zsuraski Make POST handling the way it should be. RFC1867, and any future POST h...
zsuraski authored
269 }
270 }
271
7429c2d @rlerdorf Input Filter support. See README.input_filter for details.
rlerdorf authored
272 SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter)
273 {
274 /* TODO: check .ini setting here and apply user-defined input filter */
c354544 @rlerdorf I could have sworn I committed this a while ago. Just a tiny NULL safet...
rlerdorf authored
275 if(new_val_len) *new_val_len = val_len;
74eed61 - Fix the default SAPI filter too; all weird problems should be gone aga...
Derick Rethans authored
276 return 1;
7429c2d @rlerdorf Input Filter support. See README.input_filter for details.
rlerdorf authored
277 }
278
7527bf0 made sapi_register_treat_data() to support multibyte input encoding tran...
Rui Hirokawa authored
279 SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data)
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
280 {
e642d18 ws, pval -> zval
foobar authored
281 char *res = NULL, *var, *val, *separator = NULL;
43ff395 Const'ify part of sapi_request_info.
Sascha Schumann authored
282 const char *c_var;
e642d18 ws, pval -> zval
foobar authored
283 zval *array_ptr;
284 int free_buffer = 0;
3881904 Replace strtok with strtok_r
Sascha Schumann authored
285 char *strtok_buf = NULL;
2ad7f44 Improved max_input_vars directive to check nested variables
Dmitry Stogov authored
286 long count = 0;
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
287
288 switch (arg) {
289 case PARSE_POST:
290 case PARSE_GET:
291 case PARSE_COOKIE:
eb32144 @zsuraski - Remove track_vars - it is now always on
zsuraski authored
292 ALLOC_ZVAL(array_ptr);
293 array_init(array_ptr);
294 INIT_PZVAL(array_ptr);
295 switch (arg) {
296 case PARSE_POST:
28446a4 Fixed "refcount" counting for autoglobals
Dmitry Stogov authored
297 if (PG(http_globals)[TRACK_VARS_POST]) {
298 zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_POST]);
299 }
eb32144 @zsuraski - Remove track_vars - it is now always on
zsuraski authored
300 PG(http_globals)[TRACK_VARS_POST] = array_ptr;
301 break;
302 case PARSE_GET:
28446a4 Fixed "refcount" counting for autoglobals
Dmitry Stogov authored
303 if (PG(http_globals)[TRACK_VARS_GET]) {
304 zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_GET]);
305 }
eb32144 @zsuraski - Remove track_vars - it is now always on
zsuraski authored
306 PG(http_globals)[TRACK_VARS_GET] = array_ptr;
307 break;
308 case PARSE_COOKIE:
28446a4 Fixed "refcount" counting for autoglobals
Dmitry Stogov authored
309 if (PG(http_globals)[TRACK_VARS_COOKIE]) {
310 zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_COOKIE]);
311 }
eb32144 @zsuraski - Remove track_vars - it is now always on
zsuraski authored
312 PG(http_globals)[TRACK_VARS_COOKIE] = array_ptr;
313 break;
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
314 }
315 break;
316 default:
e642d18 ws, pval -> zval
foobar authored
317 array_ptr = destArray;
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
318 break;
319 }
320
e642d18 ws, pval -> zval
foobar authored
321 if (arg == PARSE_POST) {
d87cc97 @zsuraski Redesigned thread safety mechanism - nua nua
zsuraski authored
322 sapi_handle_post(array_ptr TSRMLS_CC);
a6393de @zsuraski Make POST handling the way it should be. RFC1867, and any future POST h...
zsuraski authored
323 return;
324 }
325
326 if (arg == PARSE_GET) { /* GET data */
43ff395 Const'ify part of sapi_request_info.
Sascha Schumann authored
327 c_var = SG(request_info).query_string;
328 if (c_var && *c_var) {
329 res = (char *) estrdup(c_var);
4079f91 @andigutmans * Make read_post() read input by chunks instead of returning a single st...
andigutmans authored
330 free_buffer = 1;
331 } else {
332 free_buffer = 0;
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
333 }
334 } else if (arg == PARSE_COOKIE) { /* Cookie data */
43ff395 Const'ify part of sapi_request_info.
Sascha Schumann authored
335 c_var = SG(request_info).cookie_data;
336 if (c_var && *c_var) {
337 res = (char *) estrdup(c_var);
4079f91 @andigutmans * Make read_post() read input by chunks instead of returning a single st...
andigutmans authored
338 free_buffer = 1;
339 } else {
340 free_buffer = 0;
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
341 }
342 } else if (arg == PARSE_STRING) { /* String data */
343 res = str;
4079f91 @andigutmans * Make read_post() read input by chunks instead of returning a single st...
andigutmans authored
344 free_buffer = 1;
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
345 }
a6393de @zsuraski Make POST handling the way it should be. RFC1867, and any future POST h...
zsuraski authored
346
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
347 if (!res) {
348 return;
349 }
350
c34d2b9 Added new configuration directives:
foobar authored
351 switch (arg) {
352 case PARSE_GET:
353 case PARSE_STRING:
354 separator = (char *) estrdup(PG(arg_separator).input);
355 break;
356 case PARSE_COOKIE:
e77c65f Revert cookie patch for BC reasons.
Ilia Alshanetsky authored
357 separator = ";\0";
c34d2b9 Added new configuration directives:
foobar authored
358 break;
359 }
360
460293f Cookies use ; as argument separator.
foobar authored
361 var = php_strtok_r(res, separator, &strtok_buf);
362
a6393de @zsuraski Make POST handling the way it should be. RFC1867, and any future POST h...
zsuraski authored
363 while (var) {
364 val = strchr(var, '=');
847741c Strip leading spaces from cookie names, that can come from multi-cookie
Ilia Alshanetsky authored
365
366 if (arg == PARSE_COOKIE) {
367 /* Remove leading spaces from cookie names, needed for multi-cookie header where ; can be followed by a space */
368 while (isspace(*var)) {
369 var++;
370 }
371 if (var == val || *var == '\0') {
372 goto next_cookie;
373 }
374 }
375
2ad7f44 Improved max_input_vars directive to check nested variables
Dmitry Stogov authored
376 if (++count > PG(max_input_vars)) {
377 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variables exceeded %ld. To increase the limit change max_input_vars in php.ini.", PG(max_input_vars));
378 break;
379 }
380
a6393de @zsuraski Make POST handling the way it should be. RFC1867, and any future POST h...
zsuraski authored
381 if (val) { /* have a value */
0731f54 @smalyshev Fix #7987: POST/GET: string with \0(%00) values not parsed correctly
smalyshev authored
382 int val_len;
750b033 - Fix sapi_input_filter patch. Returning 1 from the filter handler shoul...
Derick Rethans authored
383 unsigned int new_val_len;
0731f54 @smalyshev Fix #7987: POST/GET: string with \0(%00) values not parsed correctly
smalyshev authored
384
a6393de @zsuraski Make POST handling the way it should be. RFC1867, and any future POST h...
zsuraski authored
385 *val++ = '\0';
386 php_url_decode(var, strlen(var));
b83255a Fix last commit. This line isn't supposed to be replaced.
Yasuo Ohgaki authored
387 val_len = php_url_decode(val, strlen(val));
59d55ef As long we pass values by reference this is needed. Ugly!
Stefan Esser authored
388 val = estrndup(val, val_len);
8c075de Fixed: PARSE_TYPE parameter to input_filter
Stefan Esser authored
389 if (sapi_module.input_filter(arg, var, &val, val_len, &new_val_len TSRMLS_CC)) {
750b033 - Fix sapi_input_filter patch. Returning 1 from the filter handler shoul...
Derick Rethans authored
390 php_register_variable_safe(var, val, new_val_len, array_ptr TSRMLS_CC);
370dfd3 - Prevent registration of the variable when a zero-length is returned
Derick Rethans authored
391 }
59d55ef As long we pass values by reference this is needed. Ugly!
Stefan Esser authored
392 efree(val);
a842e12 @zsuraski Fix for non-mbstring builds. Bad Yasuo! :)
zsuraski authored
393 } else {
0e8de75 Ooups...
Stefan Esser authored
394 int val_len;
395 unsigned int new_val_len;
396
17e0d9c MFB
Yasuo Ohgaki authored
397 php_url_decode(var, strlen(var));
8c075de Fixed: PARSE_TYPE parameter to input_filter
Stefan Esser authored
398 val_len = 0;
399 val = estrndup("", val_len);
400 if (sapi_module.input_filter(arg, var, &val, val_len, &new_val_len TSRMLS_CC)) {
401 php_register_variable_safe(var, val, new_val_len, array_ptr TSRMLS_CC);
402 }
403 efree(val);
92e542d Fixed some.php?a&b&c does not initilize $_GET['a'], $_GET['b'], $_GET['c...
Yasuo Ohgaki authored
404 }
847741c Strip leading spaces from cookie names, that can come from multi-cookie
Ilia Alshanetsky authored
405 next_cookie:
460293f Cookies use ; as argument separator.
foobar authored
406 var = php_strtok_r(NULL, separator, &strtok_buf);
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
407 }
c34d2b9 Added new configuration directives:
foobar authored
408
e642d18 ws, pval -> zval
foobar authored
409 if (arg != PARSE_COOKIE) {
c34d2b9 Added new configuration directives:
foobar authored
410 efree(separator);
411 }
412
4079f91 @andigutmans * Make read_post() read input by chunks instead of returning a single st...
andigutmans authored
413 if (free_buffer) {
414 efree(res);
415 }
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
416 }
417
96b9c0a make php_import_environment_variables overwritable so fastcgi can correc...
Shane Caraveo authored
418 void _php_import_environment_variables(zval *array_ptr TSRMLS_DC)
9ab35ae @zsuraski Tried to centralize global variable registration as much as possible:
zsuraski authored
419 {
961ad8e Improved php_import_environment_variables: avoid emalloc()ing in most ca...
Moriyoshi Koizumi authored
420 char buf[128];
421 char **env, *p, *t = buf;
422 size_t alloc_size = sizeof(buf);
e1eb238 On 64bit platforms, pointers are 64bit long..
Moriyoshi Koizumi authored
423 unsigned long nlen; /* ptrdiff_t is not portable */
961ad8e Improved php_import_environment_variables: avoid emalloc()ing in most ca...
Moriyoshi Koizumi authored
424
9ab35ae @zsuraski Tried to centralize global variable registration as much as possible:
zsuraski authored
425 for (env = environ; env != NULL && *env != NULL; env++) {
426 p = strchr(*env, '=');
427 if (!p) { /* malformed entry? */
428 continue;
429 }
961ad8e Improved php_import_environment_variables: avoid emalloc()ing in most ca...
Moriyoshi Koizumi authored
430 nlen = p - *env;
431 if (nlen >= alloc_size) {
432 alloc_size = nlen + 64;
433 t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size));
434 }
435 memcpy(t, *env, nlen);
436 t[nlen] = '\0';
e642d18 ws, pval -> zval
foobar authored
437 php_register_variable(t, p + 1, array_ptr TSRMLS_CC);
961ad8e Improved php_import_environment_variables: avoid emalloc()ing in most ca...
Moriyoshi Koizumi authored
438 }
439 if (t != buf && t != NULL) {
9ab35ae @zsuraski Tried to centralize global variable registration as much as possible:
zsuraski authored
440 efree(t);
441 }
442 }
443
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
444 zend_bool php_std_auto_global_callback(char *name, uint name_len TSRMLS_DC)
445 {
446 zend_printf("%s\n", name);
447 return 0; /* don't rearm */
448 }
449
450 /* {{{ php_build_argv
451 */
452 static void php_build_argv(char *s, zval *track_vars_array TSRMLS_DC)
453 {
e642d18 ws, pval -> zval
foobar authored
454 zval *arr, *argc, *tmp;
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
455 int count = 0;
456 char *ss, *space;
457
febee11 @KalleZ Removed register_globals
KalleZ authored
458 if (!(SG(request_info).argc || track_vars_array)) {
b3920d5 Made the $argc and $argv always available as globals in CLI, and not as
Andrei Zmievski authored
459 return;
460 }
461
73e4913 Fixed memory leaks
Dmitry Stogov authored
462 ALLOC_INIT_ZVAL(arr);
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
463 array_init(arr);
464
465 /* Prepare argv */
466 if (SG(request_info).argc) { /* are we in cli sapi? */
467 int i;
e642d18 ws, pval -> zval
foobar authored
468 for (i = 0; i < SG(request_info).argc; i++) {
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
469 ALLOC_ZVAL(tmp);
470 Z_TYPE_P(tmp) = IS_STRING;
471 Z_STRLEN_P(tmp) = strlen(SG(request_info).argv[i]);
472 Z_STRVAL_P(tmp) = estrndup(SG(request_info).argv[i], Z_STRLEN_P(tmp));
473 INIT_PZVAL(tmp);
e642d18 ws, pval -> zval
foobar authored
474 if (zend_hash_next_index_insert(Z_ARRVAL_P(arr), &tmp, sizeof(zval *), NULL) == FAILURE) {
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
475 if (Z_TYPE_P(tmp) == IS_STRING) {
476 efree(Z_STRVAL_P(tmp));
477 }
478 }
479 }
480 } else if (s && *s) {
481 ss = s;
482 while (ss) {
483 space = strchr(ss, '+');
484 if (space) {
485 *space = '\0';
486 }
487 /* auto-type */
488 ALLOC_ZVAL(tmp);
489 Z_TYPE_P(tmp) = IS_STRING;
490 Z_STRLEN_P(tmp) = strlen(ss);
491 Z_STRVAL_P(tmp) = estrndup(ss, Z_STRLEN_P(tmp));
492 INIT_PZVAL(tmp);
493 count++;
e642d18 ws, pval -> zval
foobar authored
494 if (zend_hash_next_index_insert(Z_ARRVAL_P(arr), &tmp, sizeof(zval *), NULL) == FAILURE) {
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
495 if (Z_TYPE_P(tmp) == IS_STRING) {
496 efree(Z_STRVAL_P(tmp));
497 }
498 }
499 if (space) {
500 *space = '+';
501 ss = space + 1;
502 } else {
503 ss = space;
504 }
505 }
506 }
507
508 /* prepare argc */
73e4913 Fixed memory leaks
Dmitry Stogov authored
509 ALLOC_INIT_ZVAL(argc);
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
510 if (SG(request_info).argc) {
511 Z_LVAL_P(argc) = SG(request_info).argc;
512 } else {
513 Z_LVAL_P(argc) = count;
514 }
515 Z_TYPE_P(argc) = IS_LONG;
516
febee11 @KalleZ Removed register_globals
KalleZ authored
517 if (SG(request_info).argc) {
4b4d634 MFH: Added macros for managing zval refcounts and is_ref statuses
Yiduo (David) Wang authored
518 Z_ADDREF_P(arr);
519 Z_ADDREF_P(argc);
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
520 zend_hash_update(&EG(symbol_table), "argv", sizeof("argv"), &arr, sizeof(zval *), NULL);
521 zend_hash_add(&EG(symbol_table), "argc", sizeof("argc"), &argc, sizeof(zval *), NULL);
dd7bdcf @smalyshev Fix $_SERVER['argv'] and $_SERVER['argc']
smalyshev authored
522 }
523 if (track_vars_array) {
4b4d634 MFH: Added macros for managing zval refcounts and is_ref statuses
Yiduo (David) Wang authored
524 Z_ADDREF_P(arr);
525 Z_ADDREF_P(argc);
e642d18 ws, pval -> zval
foobar authored
526 zend_hash_update(Z_ARRVAL_P(track_vars_array), "argv", sizeof("argv"), &arr, sizeof(zval *), NULL);
527 zend_hash_update(Z_ARRVAL_P(track_vars_array), "argc", sizeof("argc"), &argc, sizeof(zval *), NULL);
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
528 }
73e4913 Fixed memory leaks
Dmitry Stogov authored
529 zval_ptr_dtor(&arr);
530 zval_ptr_dtor(&argc);
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
531 }
532 /* }}} */
533
534 /* {{{ php_register_server_variables
535 */
536 static inline void php_register_server_variables(TSRMLS_D)
537 {
e642d18 ws, pval -> zval
foobar authored
538 zval *array_ptr = NULL;
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
539
540 ALLOC_ZVAL(array_ptr);
541 array_init(array_ptr);
542 INIT_PZVAL(array_ptr);
28446a4 Fixed "refcount" counting for autoglobals
Dmitry Stogov authored
543 if (PG(http_globals)[TRACK_VARS_SERVER]) {
544 zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]);
545 }
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
546 PG(http_globals)[TRACK_VARS_SERVER] = array_ptr;
547
548 /* Server variables */
549 if (sapi_module.register_server_variables) {
550 sapi_module.register_server_variables(array_ptr TSRMLS_CC);
551 }
552
553 /* PHP Authentication support */
554 if (SG(request_info).auth_user) {
555 php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, array_ptr TSRMLS_CC);
556 }
557 if (SG(request_info).auth_password) {
558 php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password, array_ptr TSRMLS_CC);
559 }
8235a70 added a server variable PHP_AUTH_DIGEST to support HTTP Digest Authentic...
Rui Hirokawa authored
560 if (SG(request_info).auth_digest) {
561 php_register_variable("PHP_AUTH_DIGEST", SG(request_info).auth_digest, array_ptr TSRMLS_CC);
562 }
0802b12 Make request start time be available via $_SERVER['REQUEST_TIME'].
Ilia Alshanetsky authored
563 /* store request init time */
564 {
a430521 @patrickallaert Changed: restoring REQUEST_TIME as a long, introducing REQUEST_TIME_FLOA...
patrickallaert authored
565 zval request_time_float, request_time_long;
566 Z_TYPE(request_time_float) = IS_DOUBLE;
567 Z_DVAL(request_time_float) = sapi_get_request_time(TSRMLS_C);
568 php_register_variable_ex("REQUEST_TIME_FLOAT", &request_time_float, array_ptr TSRMLS_CC);
569 Z_TYPE(request_time_long) = IS_LONG;
570 Z_LVAL(request_time_long) = zend_dval_to_lval(Z_DVAL(request_time_float));
571 php_register_variable_ex("REQUEST_TIME", &request_time_long, array_ptr TSRMLS_CC);
0802b12 Make request start time be available via $_SERVER['REQUEST_TIME'].
Ilia Alshanetsky authored
572 }
573
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
574 }
575 /* }}} */
576
023c8a7 @zsuraski Fix register_globals
zsuraski authored
577 /* {{{ php_autoglobal_merge
578 */
579 static void php_autoglobal_merge(HashTable *dest, HashTable *src TSRMLS_DC)
580 {
0a49c03 @zsuraski - Use the new infrastructure of zend_symtable_*() (fixes bug #24565)
zsuraski authored
581 zval **src_entry, **dest_entry;
582 char *string_key;
583 uint string_key_len;
584 ulong num_key;
585 HashPosition pos;
586 int key_type;
febee11 @KalleZ Removed register_globals
KalleZ authored
587 int globals_check = (dest == (&EG(symbol_table)));
023c8a7 @zsuraski Fix register_globals
zsuraski authored
588
589 zend_hash_internal_pointer_reset_ex(src, &pos);
590 while (zend_hash_get_current_data_ex(src, (void **)&src_entry, &pos) == SUCCESS) {
591 key_type = zend_hash_get_current_key_ex(src, &string_key, &string_key_len, &num_key, 0, &pos);
0a49c03 @zsuraski - Use the new infrastructure of zend_symtable_*() (fixes bug #24565)
zsuraski authored
592 if (Z_TYPE_PP(src_entry) != IS_ARRAY
e642d18 ws, pval -> zval
foobar authored
593 || (key_type == HASH_KEY_IS_STRING && zend_hash_find(dest, string_key, string_key_len, (void **) &dest_entry) != SUCCESS)
594 || (key_type == HASH_KEY_IS_LONG && zend_hash_index_find(dest, num_key, (void **)&dest_entry) != SUCCESS)
595 || Z_TYPE_PP(dest_entry) != IS_ARRAY
0484855 @pierrejoye - ws
pierrejoye authored
596 ) {
4b4d634 MFH: Added macros for managing zval refcounts and is_ref statuses
Yiduo (David) Wang authored
597 Z_ADDREF_PP(src_entry);
023c8a7 @zsuraski Fix register_globals
zsuraski authored
598 if (key_type == HASH_KEY_IS_STRING) {
ed9e8c7 Fixed bug #31440 ($GLOBALS can be overwritten via GPC when register_glob...
Ilia Alshanetsky authored
599 if (!globals_check || string_key_len != sizeof("GLOBALS") || memcmp(string_key, "GLOBALS", sizeof("GLOBALS") - 1)) {
600 zend_hash_update(dest, string_key, string_key_len, src_entry, sizeof(zval *), NULL);
601 } else {
4b4d634 MFH: Added macros for managing zval refcounts and is_ref statuses
Yiduo (David) Wang authored
602 Z_DELREF_PP(src_entry);
ed9e8c7 Fixed bug #31440 ($GLOBALS can be overwritten via GPC when register_glob...
Ilia Alshanetsky authored
603 }
023c8a7 @zsuraski Fix register_globals
zsuraski authored
604 } else {
605 zend_hash_index_update(dest, num_key, src_entry, sizeof(zval *), NULL);
606 }
607 } else {
608 SEPARATE_ZVAL(dest_entry);
609 php_autoglobal_merge(Z_ARRVAL_PP(dest_entry), Z_ARRVAL_PP(src_entry) TSRMLS_CC);
610 }
611 zend_hash_move_forward_ex(src, &pos);
612 }
613 }
614 /* }}} */
615
e43ff13 Fixed ZE specific compile warnings (Bug #55629)
Dmitry Stogov authored
616 static zend_bool php_auto_globals_create_server(const char *name, uint name_len TSRMLS_DC);
617 static zend_bool php_auto_globals_create_env(const char *name, uint name_len TSRMLS_DC);
618 static zend_bool php_auto_globals_create_request(const char *name, uint name_len TSRMLS_DC);
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
619
620 /* {{{ php_hash_environment
621 */
622 int php_hash_environment(TSRMLS_D)
623 {
f0c8366 - use interned strings for auto globals
Dmitry Stogov authored
624 memset(PG(http_globals), 0, sizeof(PG(http_globals)));
625 zend_activate_auto_globals(TSRMLS_C);
b3920d5 Made the $argc and $argv always available as globals in CLI, and not as
Andrei Zmievski authored
626 if (PG(register_argc_argv)) {
627 php_build_argv(SG(request_info).query_string, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
628 }
f0c8366 - use interned strings for auto globals
Dmitry Stogov authored
629 return SUCCESS;
630 }
631 /* }}} */
b3920d5 Made the $argc and $argv always available as globals in CLI, and not as
Andrei Zmievski authored
632
e43ff13 Fixed ZE specific compile warnings (Bug #55629)
Dmitry Stogov authored
633 static zend_bool php_auto_globals_create_get(const char *name, uint name_len TSRMLS_DC)
f0c8366 - use interned strings for auto globals
Dmitry Stogov authored
634 {
635 zval *vars;
636
637 if (PG(variables_order) && (strchr(PG(variables_order),'G') || strchr(PG(variables_order),'g'))) {
638 sapi_module.treat_data(PARSE_GET, NULL, NULL TSRMLS_CC);
639 vars = PG(http_globals)[TRACK_VARS_GET];
640 } else {
641 ALLOC_ZVAL(vars);
642 array_init(vars);
643 INIT_PZVAL(vars);
644 if (PG(http_globals)[TRACK_VARS_GET]) {
645 zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_GET]);
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
646 }
f0c8366 - use interned strings for auto globals
Dmitry Stogov authored
647 PG(http_globals)[TRACK_VARS_GET] = vars;
648 }
649
650 zend_hash_update(&EG(symbol_table), name, name_len + 1, &vars, sizeof(zval *), NULL);
651 Z_ADDREF_P(vars);
652
653 return 0; /* don't rearm */
654 }
655
e43ff13 Fixed ZE specific compile warnings (Bug #55629)
Dmitry Stogov authored
656 static zend_bool php_auto_globals_create_post(const char *name, uint name_len TSRMLS_DC)
f0c8366 - use interned strings for auto globals
Dmitry Stogov authored
657 {
658 zval *vars;
659
660 if (PG(variables_order) &&
0484855 @pierrejoye - ws
pierrejoye authored
661 (strchr(PG(variables_order),'P') || strchr(PG(variables_order),'p')) &&
f0c8366 - use interned strings for auto globals
Dmitry Stogov authored
662 !SG(headers_sent) &&
663 SG(request_info).request_method &&
664 !strcasecmp(SG(request_info).request_method, "POST")) {
665 sapi_module.treat_data(PARSE_POST, NULL, NULL TSRMLS_CC);
666 vars = PG(http_globals)[TRACK_VARS_POST];
667 } else {
668 ALLOC_ZVAL(vars);
669 array_init(vars);
670 INIT_PZVAL(vars);
671 if (PG(http_globals)[TRACK_VARS_POST]) {
672 zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_POST]);
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
673 }
f0c8366 - use interned strings for auto globals
Dmitry Stogov authored
674 PG(http_globals)[TRACK_VARS_POST] = vars;
675 }
676
677 zend_hash_update(&EG(symbol_table), name, name_len + 1, &vars, sizeof(zval *), NULL);
678 Z_ADDREF_P(vars);
679
680 return 0; /* don't rearm */
681 }
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
682
e43ff13 Fixed ZE specific compile warnings (Bug #55629)
Dmitry Stogov authored
683 static zend_bool php_auto_globals_create_cookie(const char *name, uint name_len TSRMLS_DC)
f0c8366 - use interned strings for auto globals
Dmitry Stogov authored
684 {
685 zval *vars;
686
687 if (PG(variables_order) && (strchr(PG(variables_order),'C') || strchr(PG(variables_order),'c'))) {
688 sapi_module.treat_data(PARSE_COOKIE, NULL, NULL TSRMLS_CC);
689 vars = PG(http_globals)[TRACK_VARS_COOKIE];
690 } else {
691 ALLOC_ZVAL(vars);
692 array_init(vars);
693 INIT_PZVAL(vars);
694 if (PG(http_globals)[TRACK_VARS_COOKIE]) {
695 zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_COOKIE]);
696 }
697 PG(http_globals)[TRACK_VARS_COOKIE] = vars;
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
698 }
699
f0c8366 - use interned strings for auto globals
Dmitry Stogov authored
700 zend_hash_update(&EG(symbol_table), name, name_len + 1, &vars, sizeof(zval *), NULL);
701 Z_ADDREF_P(vars);
702
703 return 0; /* don't rearm */
704 }
705
e43ff13 Fixed ZE specific compile warnings (Bug #55629)
Dmitry Stogov authored
706 static zend_bool php_auto_globals_create_files(const char *name, uint name_len TSRMLS_DC)
f0c8366 - use interned strings for auto globals
Dmitry Stogov authored
707 {
708 zval *vars;
709
710 if (PG(http_globals)[TRACK_VARS_FILES]) {
711 vars = PG(http_globals)[TRACK_VARS_FILES];
712 } else {
713 ALLOC_ZVAL(vars);
714 array_init(vars);
715 INIT_PZVAL(vars);
716 PG(http_globals)[TRACK_VARS_FILES] = vars;
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
717 }
718
f0c8366 - use interned strings for auto globals
Dmitry Stogov authored
719 zend_hash_update(&EG(symbol_table), name, name_len + 1, &vars, sizeof(zval *), NULL);
720 Z_ADDREF_P(vars);
721
722 return 0; /* don't rearm */
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
723 }
724
e43ff13 Fixed ZE specific compile warnings (Bug #55629)
Dmitry Stogov authored
725 static zend_bool php_auto_globals_create_server(const char *name, uint name_len TSRMLS_DC)
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
726 {
5f88099 MFH: Fixed bug #34331 (php crashes when variables_order is empty).
Ilia Alshanetsky authored
727 if (PG(variables_order) && (strchr(PG(variables_order),'S') || strchr(PG(variables_order),'s'))) {
1add2cc Fixed bug #29971 (variables_order behaviour)
Dmitry Stogov authored
728 php_register_server_variables(TSRMLS_C);
d355704 Fixed register_argc_argv behavior. Now it behave in the same way as befo...
Dmitry Stogov authored
729
730 if (PG(register_argc_argv)) {
731 if (SG(request_info).argc) {
732 zval **argc, **argv;
733
734 if (zend_hash_find(&EG(symbol_table), "argc", sizeof("argc"), (void**)&argc) == SUCCESS &&
0484855 @pierrejoye - ws
pierrejoye authored
735 zend_hash_find(&EG(symbol_table), "argv", sizeof("argv"), (void**)&argv) == SUCCESS) {
4b4d634 MFH: Added macros for managing zval refcounts and is_ref statuses
Yiduo (David) Wang authored
736 Z_ADDREF_PP(argc);
737 Z_ADDREF_PP(argv);
d355704 Fixed register_argc_argv behavior. Now it behave in the same way as befo...
Dmitry Stogov authored
738 zend_hash_update(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv"), argv, sizeof(zval *), NULL);
739 zend_hash_update(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "argc", sizeof("argc"), argc, sizeof(zval *), NULL);
740 }
741 } else {
742 php_build_argv(SG(request_info).query_string, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
743 }
744 }
745
1add2cc Fixed bug #29971 (variables_order behaviour)
Dmitry Stogov authored
746 } else {
747 zval *server_vars=NULL;
748 ALLOC_ZVAL(server_vars);
749 array_init(server_vars);
750 INIT_PZVAL(server_vars);
28446a4 Fixed "refcount" counting for autoglobals
Dmitry Stogov authored
751 if (PG(http_globals)[TRACK_VARS_SERVER]) {
752 zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]);
753 }
1add2cc Fixed bug #29971 (variables_order behaviour)
Dmitry Stogov authored
754 PG(http_globals)[TRACK_VARS_SERVER] = server_vars;
755 }
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
756
e642d18 ws, pval -> zval
foobar authored
757 zend_hash_update(&EG(symbol_table), name, name_len + 1, &PG(http_globals)[TRACK_VARS_SERVER], sizeof(zval *), NULL);
4b4d634 MFH: Added macros for managing zval refcounts and is_ref statuses
Yiduo (David) Wang authored
758 Z_ADDREF_P(PG(http_globals)[TRACK_VARS_SERVER]);
d355704 Fixed register_argc_argv behavior. Now it behave in the same way as befo...
Dmitry Stogov authored
759
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
760 return 0; /* don't rearm */
761 }
762
e43ff13 Fixed ZE specific compile warnings (Bug #55629)
Dmitry Stogov authored
763 static zend_bool php_auto_globals_create_env(const char *name, uint name_len TSRMLS_DC)
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
764 {
e642d18 ws, pval -> zval
foobar authored
765 zval *env_vars = NULL;
e5cfb1d @andigutmans - Better stability during premature shutdown of request startup
andigutmans authored
766 ALLOC_ZVAL(env_vars);
767 array_init(env_vars);
768 INIT_PZVAL(env_vars);
28446a4 Fixed "refcount" counting for autoglobals
Dmitry Stogov authored
769 if (PG(http_globals)[TRACK_VARS_ENV]) {
770 zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_ENV]);
771 }
e5cfb1d @andigutmans - Better stability during premature shutdown of request startup
andigutmans authored
772 PG(http_globals)[TRACK_VARS_ENV] = env_vars;
773
5f88099 MFH: Fixed bug #34331 (php crashes when variables_order is empty).
Ilia Alshanetsky authored
774 if (PG(variables_order) && (strchr(PG(variables_order),'E') || strchr(PG(variables_order),'e'))) {
1add2cc Fixed bug #29971 (variables_order behaviour)
Dmitry Stogov authored
775 php_import_environment_variables(PG(http_globals)[TRACK_VARS_ENV] TSRMLS_CC);
776 }
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
777
e642d18 ws, pval -> zval
foobar authored
778 zend_hash_update(&EG(symbol_table), name, name_len + 1, &PG(http_globals)[TRACK_VARS_ENV], sizeof(zval *), NULL);
4b4d634 MFH: Added macros for managing zval refcounts and is_ref statuses
Yiduo (David) Wang authored
779 Z_ADDREF_P(PG(http_globals)[TRACK_VARS_ENV]);
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
780
781 return 0; /* don't rearm */
782 }
783
e43ff13 Fixed ZE specific compile warnings (Bug #55629)
Dmitry Stogov authored
784 static zend_bool php_auto_globals_create_request(const char *name, uint name_len TSRMLS_DC)
622da33 @zsuraski - Optimize $_REQUEST
zsuraski authored
785 {
786 zval *form_variables;
0eb76eb Fixed bug #24883 (variables created through register_globals, ignore
Ilia Alshanetsky authored
787 unsigned char _gpc_flags[3] = {0, 0, 0};
622da33 @zsuraski - Optimize $_REQUEST
zsuraski authored
788 char *p;
789
790 ALLOC_ZVAL(form_variables);
791 array_init(form_variables);
792 INIT_PZVAL(form_variables);
793
2f27a0b - Cleanup
Jani Taskinen authored
794 if (PG(request_order) != NULL) {
a9fe101 @smalyshev [DOC] add request_order INI variable to control $_REQUEST content
smalyshev authored
795 p = PG(request_order);
796 } else {
797 p = PG(variables_order);
798 }
799
800 for (; p && *p; p++) {
622da33 @zsuraski - Optimize $_REQUEST
zsuraski authored
801 switch (*p) {
802 case 'g':
803 case 'G':
0eb76eb Fixed bug #24883 (variables created through register_globals, ignore
Ilia Alshanetsky authored
804 if (!_gpc_flags[0]) {
805 php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]) TSRMLS_CC);
806 _gpc_flags[0] = 1;
807 }
622da33 @zsuraski - Optimize $_REQUEST
zsuraski authored
808 break;
809 case 'p':
810 case 'P':
0eb76eb Fixed bug #24883 (variables created through register_globals, ignore
Ilia Alshanetsky authored
811 if (!_gpc_flags[1]) {
812 php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]) TSRMLS_CC);
813 _gpc_flags[1] = 1;
814 }
622da33 @zsuraski - Optimize $_REQUEST
zsuraski authored
815 break;
816 case 'c':
817 case 'C':
0eb76eb Fixed bug #24883 (variables created through register_globals, ignore
Ilia Alshanetsky authored
818 if (!_gpc_flags[2]) {
819 php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]) TSRMLS_CC);
820 _gpc_flags[2] = 1;
821 }
622da33 @zsuraski - Optimize $_REQUEST
zsuraski authored
822 break;
823 }
824 }
825
f0c8366 - use interned strings for auto globals
Dmitry Stogov authored
826 zend_hash_update(&EG(symbol_table), name, name_len + 1, &form_variables, sizeof(zval *), NULL);
622da33 @zsuraski - Optimize $_REQUEST
zsuraski authored
827 return 0;
828 }
829
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
830 void php_startup_auto_globals(TSRMLS_D)
831 {
2f27a0b - Cleanup
Jani Taskinen authored
832 zend_register_auto_global(ZEND_STRL("_GET"), 0, php_auto_globals_create_get TSRMLS_CC);
833 zend_register_auto_global(ZEND_STRL("_POST"), 0, php_auto_globals_create_post TSRMLS_CC);
834 zend_register_auto_global(ZEND_STRL("_COOKIE"), 0, php_auto_globals_create_cookie TSRMLS_CC);
835 zend_register_auto_global(ZEND_STRL("_SERVER"), PG(auto_globals_jit), php_auto_globals_create_server TSRMLS_CC);
836 zend_register_auto_global(ZEND_STRL("_ENV"), PG(auto_globals_jit), php_auto_globals_create_env TSRMLS_CC);
837 zend_register_auto_global(ZEND_STRL("_REQUEST"), PG(auto_globals_jit), php_auto_globals_create_request TSRMLS_CC);
838 zend_register_auto_global(ZEND_STRL("_FILES"), 0, php_auto_globals_create_files TSRMLS_CC);
4e55747 @zsuraski Add JIT initialization for _SERVER and _ENV
zsuraski authored
839 }
840
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
841 /*
842 * Local variables:
843 * tab-width: 4
844 * c-basic-offset: 4
845 * End:
78747bd - Don't wrap lines... this is annoying while coding.
Derick Rethans authored
846 * vim600: sw=4 ts=4 fdm=marker
847 * vim<600: sw=4 ts=4
2c0ad3e last bunch of extensions moving to ext/
Stig Bakken authored
848 */
Something went wrong with that request. Please try again.