1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 6 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 The PHP Group |
6 : +----------------------------------------------------------------------+
7 : | This source file is subject to version 3.01 of the PHP license, |
8 : | that is bundled with this package in the file LICENSE, and is |
9 : | available through the world-wide-web at the following url: |
10 : | http://www.php.net/license/3_01.txt |
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. |
14 : +----------------------------------------------------------------------+
15 : | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
16 : | Zeev Suraski <zeev@zend.com> |
17 : +----------------------------------------------------------------------+
18 : */
19 :
20 : /* $Id: php_variables.c 281233 2009-05-27 14:53:05Z tony2001 $ */
21 :
22 : #include <stdio.h>
23 : #include "php.h"
24 : #include "ext/standard/php_standard.h"
25 : #include "ext/standard/credits.h"
26 : #include "php_variables.h"
27 : #include "php_globals.h"
28 : #include "php_content_types.h"
29 : #include "SAPI.h"
30 : #include "php_logos.h"
31 : #include "zend_globals.h"
32 : #include "rfc1867.h"
33 :
34 : /* for systems that need to override reading of environment variables */
35 : void _php_import_environment_variables(zval *array_ptr TSRMLS_DC);
36 : PHPAPI void (*php_import_environment_variables)(zval *array_ptr TSRMLS_DC) = _php_import_environment_variables;
37 : static int php_decode_raw_var_array(HashTable *raw_array, zval *track_array TSRMLS_DC);
38 :
39 : PHPAPI void php_register_variable(char *var, char *strval, zval *track_vars_array TSRMLS_DC)
40 815771 : {
41 815771 : php_register_variable_safe(IS_STRING, ZSTR(var), ZSTR(strval), strlen(strval), track_vars_array TSRMLS_CC);
42 815771 : }
43 :
44 : PHPAPI int php_register_variable_with_conv(UConverter *conv, char *var, int var_len, char *val, int val_len, zval *array_ptr, int filter_arg TSRMLS_DC)
45 274 : {
46 : zstr c_var, c_val;
47 : int c_var_len, c_val_len;
48 274 : zend_uchar type = IS_UNICODE;
49 :
50 274 : if (conv == NULL) {
51 0 : type = IS_STRING;
52 : }
53 :
54 274 : if (type == IS_UNICODE) {
55 274 : c_var.u = c_val.u = NULL;
56 274 : if (zend_string_to_unicode(conv, &c_var.u, &c_var_len, var, var_len TSRMLS_CC) == FAILURE ||
57 : zend_string_to_unicode(conv, &c_val.u, &c_val_len, val, val_len TSRMLS_CC) == FAILURE) {
58 :
59 0 : if (c_var.u) {
60 0 : efree(c_var.u);
61 : }
62 0 : if (c_val.u) {
63 0 : efree(c_val.u);
64 : }
65 0 : return FAILURE;
66 :
67 : }
68 : } else {
69 0 : c_var.s = var;
70 0 : c_var_len = var_len;
71 0 : c_val.s = val;
72 0 : c_val_len = val_len;
73 : }
74 :
75 : /* UTODO
76 : * do input filtering
77 : */
78 274 : php_register_variable_safe(type, c_var, c_val, c_val_len, array_ptr TSRMLS_CC);
79 :
80 274 : if (type == IS_UNICODE) {
81 274 : efree(c_var.u);
82 274 : efree(c_val.u);
83 : }
84 :
85 274 : return SUCCESS;
86 : }
87 :
88 : PHPAPI void php_register_variable_safe(zend_uchar type, zstr var, zstr strval, int str_len, zval *track_vars_array TSRMLS_DC)
89 816228 : {
90 : zval new_entry;
91 : assert(strval.v != NULL);
92 :
93 816228 : if (type == IS_UNICODE) {
94 : /* Prepare value */
95 412 : Z_USTRLEN(new_entry) = str_len;
96 412 : Z_USTRVAL(new_entry) = eustrndup(strval.u, Z_USTRLEN(new_entry));
97 412 : Z_TYPE(new_entry) = IS_UNICODE;
98 :
99 412 : php_u_register_variable_ex(var.u, &new_entry, track_vars_array TSRMLS_CC);
100 : } else {
101 : /* Prepare value */
102 815816 : Z_STRLEN(new_entry) = str_len;
103 815816 : Z_STRVAL(new_entry) = estrndup(strval.s, Z_STRLEN(new_entry));
104 815816 : Z_TYPE(new_entry) = IS_STRING;
105 :
106 815816 : php_register_variable_ex(var.s, &new_entry, track_vars_array TSRMLS_CC);
107 : }
108 816228 : }
109 :
110 : PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars_array TSRMLS_DC)
111 998947 : {
112 998947 : char *p = NULL;
113 : char *ip; /* index pointer */
114 : char *index;
115 : char *var, *var_orig;
116 : int var_len, index_len;
117 : zval *gpc_element, **gpc_element_p;
118 998947 : zend_bool is_array = 0;
119 998947 : HashTable *symtable1 = NULL;
120 :
121 : assert(var_name != NULL);
122 :
123 998947 : if (track_vars_array) {
124 998925 : symtable1 = Z_ARRVAL_P(track_vars_array);
125 : }
126 :
127 998947 : if (!symtable1) {
128 : /* Nothing to do */
129 22 : zval_dtor(val);
130 22 : return;
131 : }
132 :
133 : /*
134 : * Prepare variable name
135 : */
136 :
137 998925 : var_orig = estrdup(var_name);
138 998925 : var = var_orig;
139 : /* ignore leading spaces in the variable name */
140 1997853 : while (*var && *var==' ') {
141 3 : var++;
142 : }
143 :
144 : /* ensure that we don't have spaces or dots in the variable name (not binary safe) */
145 14289829 : for (p = var; *p; p++) {
146 13290914 : if (*p == ' ' || *p == '.') {
147 0 : *p='_';
148 13290914 : } else if (*p == '[') {
149 10 : is_array = 1;
150 10 : ip = p;
151 10 : *p = 0;
152 10 : break;
153 : }
154 : }
155 998925 : var_len = p - var;
156 :
157 998925 : if (var_len==0) { /* empty variable name, or variable name with a space in it */
158 1 : zval_dtor(val);
159 1 : efree(var_orig);
160 1 : return;
161 : }
162 :
163 : #if 0
164 : // Do we realy need this, now that register_globals is gone? Is it the job of this
165 : // function to guard against calls with active_symbol_table as the array?
166 : /* GLOBALS hijack attempt, reject parameter */
167 : if (symtable1 == EG(active_symbol_table) &&
168 : var_len == sizeof("GLOBALS")-1 &&
169 : !memcmp(var, "GLOBALS", sizeof("GLOBALS")-1)) {
170 : zval_dtor(val);
171 : efree(var_orig);
172 : return;
173 : }
174 : #endif
175 :
176 998924 : index = var;
177 998924 : index_len = var_len;
178 :
179 998924 : if (is_array) {
180 10 : int nest_level = 0;
181 : while (1) {
182 : char *index_s;
183 10 : int new_idx_len = 0;
184 :
185 10 : if (++nest_level > PG(max_input_nesting_level)) {
186 : HashTable *ht;
187 : /* too many levels of nesting */
188 :
189 0 : ht = Z_ARRVAL_P(track_vars_array);
190 :
191 0 : zend_hash_del(ht, var, var_len + 1);
192 0 : zval_dtor(val);
193 :
194 : /* do not output the error message to the screen,
195 : this helps us to to avoid "information disclosure" */
196 0 : if (!PG(display_errors)) {
197 0 : 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));
198 : }
199 0 : efree(var_orig);
200 0 : return;
201 : }
202 :
203 10 : ip++;
204 10 : index_s = ip;
205 10 : if (isspace(*ip)) {
206 0 : ip++;
207 : }
208 10 : if (*ip==']') {
209 10 : index_s = NULL;
210 : } else {
211 0 : ip = strchr(ip, ']');
212 0 : if (!ip) {
213 : /* PHP variables cannot contain '[' in their names, so we replace the character with a '_' */
214 0 : *(index_s - 1) = '_';
215 :
216 0 : index_len = 0;
217 0 : if (index) {
218 0 : index_len = strlen(index);
219 : }
220 0 : goto plain_var;
221 : return;
222 : }
223 0 : *ip = 0;
224 0 : new_idx_len = strlen(index_s);
225 : }
226 :
227 10 : if (!index) {
228 0 : MAKE_STD_ZVAL(gpc_element);
229 0 : array_init(gpc_element);
230 0 : zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
231 : } else {
232 10 : if (zend_symtable_find(symtable1, index, index_len + 1, (void **) &gpc_element_p) == FAILURE
233 : || Z_TYPE_PP(gpc_element_p) != IS_ARRAY) {
234 5 : MAKE_STD_ZVAL(gpc_element);
235 5 : array_init(gpc_element);
236 5 : zend_symtable_update(symtable1, index, index_len + 1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
237 : }
238 : }
239 10 : symtable1 = Z_ARRVAL_PP(gpc_element_p);
240 : /* ip pointed to the '[' character, now obtain the key */
241 10 : index = index_s;
242 10 : index_len = new_idx_len;
243 :
244 10 : ip++;
245 10 : if (*ip == '[') {
246 0 : is_array = 1;
247 0 : *ip = 0;
248 : } else {
249 10 : goto plain_var;
250 : }
251 0 : }
252 : } else {
253 998924 : plain_var:
254 998924 : MAKE_STD_ZVAL(gpc_element);
255 998924 : gpc_element->value = val->value;
256 998924 : Z_TYPE_P(gpc_element) = Z_TYPE_P(val);
257 998924 : if (!index) {
258 10 : zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
259 : } else {
260 : /*
261 : * According to rfc2965, more specific paths are listed above the less specific ones.
262 : * If we encounter a duplicate cookie name, we should skip it, since it is not possible
263 : * to have the same (plain text) cookie name for the same path and we should not overwrite
264 : * more specific cookies with the less specific ones.
265 : */
266 998914 : if (PG(http_globals)[TRACK_VARS_COOKIE] &&
267 : symtable1 == Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]) &&
268 : zend_symtable_exists(symtable1, index, index_len+1)) {
269 0 : zval_ptr_dtor(&gpc_element);
270 : } else {
271 998914 : zend_symtable_update(symtable1, index, index_len + 1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
272 : }
273 : }
274 : }
275 998924 : efree(var_orig);
276 : }
277 :
278 : PHPAPI void php_u_register_variable_ex(UChar *var, zval *val, zval *track_vars_array TSRMLS_DC)
279 490 : {
280 490 : UChar *p = NULL;
281 : UChar *ip; /* index pointer */
282 : UChar *index, *var_orig;
283 : int var_len, index_len;
284 : zval *gpc_element, **gpc_element_p;
285 : zend_bool is_array;
286 490 : HashTable *symtable1=NULL;
287 :
288 : assert(var != NULL);
289 :
290 490 : if (track_vars_array) {
291 490 : symtable1 = Z_ARRVAL_P(track_vars_array);
292 : }
293 :
294 490 : if (!symtable1) {
295 : /* Nothing to do */
296 0 : zval_dtor(val);
297 0 : return;
298 : }
299 :
300 : /*
301 : * Prepare variable name
302 : */
303 490 : var_orig = eustrdup(var);
304 490 : ip = u_strchr(var, 0x5b /*'['*/);
305 490 : if (ip) {
306 252 : is_array = 1;
307 252 : *ip = 0;
308 : } else {
309 238 : is_array = 0;
310 : }
311 : /* ignore leading spaces in the variable name */
312 982 : while (*var && *var==0x20 /*' '*/) {
313 2 : var++;
314 : }
315 490 : var_len = u_strlen(var);
316 490 : if (var_len==0) { /* empty variable name, or variable name with a space in it */
317 0 : zval_dtor(val);
318 0 : efree(var_orig);
319 0 : return;
320 : }
321 : /* ensure that we don't have spaces or dots in the variable name (not binary safe) */
322 3125 : for (p=var; *p; p++) {
323 2635 : switch(*p) {
324 : case 0x20: /*' '*/
325 : case 0x2e: /*'.'*/
326 27 : *p=0x5f; /*'_'*/
327 : break;
328 : }
329 : }
330 :
331 490 : index = var;
332 490 : index_len = var_len;
333 :
334 490 : if (is_array) {
335 252 : int nest_level = 0;
336 : while (1) {
337 : UChar *index_s;
338 292 : int new_idx_len = 0;
339 :
340 292 : if (++nest_level > PG(max_input_nesting_level)) {
341 : HashTable *ht;
342 : /* too many levels of nesting */
343 :
344 1 : ht = Z_ARRVAL_P(track_vars_array);
345 :
346 1 : zend_u_hash_del(ht, IS_UNICODE, ZSTR(var), var_len + 1);
347 1 : zval_dtor(val);
348 :
349 : /* do not output the error message to the screen,
350 : this helps us to to avoid "information disclosure" */
351 1 : if (!PG(display_errors)) {
352 1 : 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));
353 : }
354 1 : efree(var_orig);
355 1 : return;
356 : }
357 :
358 291 : ip++;
359 291 : index_s = ip;
360 291 : if (u_isspace(*ip)) {
361 0 : ip++;
362 : }
363 291 : if (*ip==0x5d /*']'*/) {
364 47 : index_s = NULL;
365 : } else {
366 244 : ip = u_strchr(ip, 0x5d /*']'*/);
367 244 : if (!ip) {
368 : /* PHP variables cannot contain '[' in their names, so we replace the character with a '_' */
369 6 : *(index_s - 1) = 0x5f; /*'_'*/
370 :
371 6 : index_len = var_len = 0;
372 6 : if (index) {
373 6 : index_len = var_len = u_strlen(index);
374 : }
375 6 : goto plain_var;
376 : return;
377 : }
378 238 : *ip = 0;
379 238 : new_idx_len = u_strlen(index_s);
380 : }
381 :
382 285 : if (!index) {
383 14 : MAKE_STD_ZVAL(gpc_element);
384 14 : array_init(gpc_element);
385 14 : zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
386 : } else {
387 271 : if (zend_u_symtable_find(symtable1, IS_UNICODE, ZSTR(index), index_len+1, (void **) &gpc_element_p)==FAILURE
388 : || Z_TYPE_PP(gpc_element_p) != IS_ARRAY) {
389 80 : MAKE_STD_ZVAL(gpc_element);
390 80 : array_init(gpc_element);
391 80 : zend_u_symtable_update(symtable1, IS_UNICODE, ZSTR(index), index_len+1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
392 : }
393 : }
394 285 : symtable1 = Z_ARRVAL_PP(gpc_element_p);
395 : /* ip pointed to the '[' character, now obtain the key */
396 285 : index = index_s;
397 285 : index_len = new_idx_len;
398 :
399 285 : ip++;
400 285 : if (*ip==0x5b /*'['*/) {
401 40 : is_array = 1;
402 40 : *ip = 0;
403 : } else {
404 245 : goto plain_var;
405 : }
406 40 : }
407 : } else {
408 489 : plain_var:
409 489 : MAKE_STD_ZVAL(gpc_element);
410 489 : gpc_element->value = val->value;
411 489 : Z_TYPE_P(gpc_element) = Z_TYPE_P(val);
412 489 : if (!index) {
413 32 : zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
414 : } else {
415 : /*
416 : * According to rfc2965, more specific paths are listed above the less specific ones.
417 : * If we encounter a duplicate cookie name, we should skip it, since it is not possible
418 : * to have the same (plain text) cookie name for the same path and we should not overwrite
419 : * more specific cookies with the less specific ones.
420 : */
421 464 : if (PG(http_globals)[TRACK_VARS_COOKIE] &&
422 : symtable1 == Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]) &&
423 : zend_u_symtable_exists(symtable1, IS_UNICODE, ZSTR(index), index_len+1)) {
424 7 : zval_ptr_dtor(&gpc_element);
425 : } else {
426 450 : zend_u_symtable_update(symtable1, IS_UNICODE, ZSTR(index), index_len+1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
427 : }
428 : }
429 : }
430 489 : efree(var_orig);
431 : }
432 :
433 : SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler)
434 18 : {
435 : char *var, *val, *e, *s, *p;
436 18 : zval *array_ptr = (zval *) arg;
437 18 : UConverter *conv = UG(request_encoding_conv);
438 :
439 18 : if (SG(request_info).post_data == NULL) {
440 1 : return;
441 : }
442 17 : PG(request_decoding_error) = 0;
443 :
444 17 : s = SG(request_info).post_data;
445 17 : e = s + SG(request_info).post_data_length;
446 :
447 79 : while (s < e && (p = memchr(s, '&', (e - s)))) {
448 45 : last_value:
449 45 : if ((val = memchr(s, '=', (p - s)))) { /* have a value */
450 : int var_len;
451 : int val_len;
452 :
453 45 : var = s;
454 45 : var_len = val - s;
455 :
456 45 : php_url_decode(var, var_len);
457 45 : val++;
458 45 : val_len = php_url_decode(val, (p - val));
459 45 : if (php_register_variable_with_conv(conv, var, var_len, val, val_len, array_ptr, PARSE_POST TSRMLS_CC) == FAILURE) {
460 0 : zend_error(E_WARNING, "Failed to decode _POST array");
461 0 : PG(request_decoding_error) = 1;
462 0 : zend_hash_clean(Z_ARRVAL_P(array_ptr));
463 0 : return;
464 : }
465 : }
466 45 : s = p + 1;
467 : }
468 34 : if (s < e) {
469 17 : p = e;
470 17 : goto last_value;
471 : }
472 : }
473 :
474 : SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter)
475 0 : {
476 : /* TODO: check .ini setting here and apply user-defined input filter */
477 0 : if (new_val_len) {
478 0 : *new_val_len = val_len;
479 : }
480 0 : return 1;
481 : }
482 :
483 : SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data)
484 17059 : {
485 17059 : char *res = NULL, *var, *val, *separator = NULL;
486 : const char *c_var;
487 : zval *array_ptr;
488 17059 : int free_buffer = 0;
489 17059 : char *strtok_buf = NULL;
490 17059 : char *arg_names[] = { "_POST", "_GET", "_COOKIE", "string" };
491 : UConverter *conv;
492 :
493 17059 : PG(request_decoding_error) = 0;
494 :
495 17059 : switch (arg) {
496 : case PARSE_POST:
497 : case PARSE_GET:
498 : case PARSE_COOKIE:
499 17031 : ALLOC_ZVAL(array_ptr);
500 17031 : array_init(array_ptr);
501 17031 : INIT_PZVAL(array_ptr);
502 17031 : switch (arg) {
503 : case PARSE_POST:
504 41 : if (PG(http_globals)[TRACK_VARS_POST]) {
505 41 : zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_POST]);
506 : }
507 41 : PG(http_globals)[TRACK_VARS_POST] = array_ptr;
508 41 : break;
509 : case PARSE_GET:
510 9 : if (PG(http_globals)[TRACK_VARS_GET]) {
511 9 : zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_GET]);
512 : }
513 9 : PG(http_globals)[TRACK_VARS_GET] = array_ptr;
514 9 : break;
515 : case PARSE_COOKIE:
516 16981 : if (PG(http_globals)[TRACK_VARS_COOKIE]) {
517 0 : zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_COOKIE]);
518 : }
519 16981 : PG(http_globals)[TRACK_VARS_COOKIE] = array_ptr;
520 : break;
521 : }
522 17031 : break;
523 : default:
524 28 : array_ptr = destArray;
525 : break;
526 : }
527 :
528 17059 : if (arg == PARSE_POST) {
529 41 : if (SG(request_info).post_entry &&
530 : SG(request_info).post_entry->post_handler == rfc1867_post_handler) {
531 :
532 22 : if (SG(rfc1867_vars) == NULL) {
533 11 : sapi_handle_post(NULL TSRMLS_CC);
534 : }
535 22 : if (SG(rfc1867_vars) != NULL) {
536 19 : PG(request_decoding_error) = 0;
537 19 : if (php_decode_raw_var_array(SG(rfc1867_vars), array_ptr TSRMLS_CC) == FAILURE) {
538 0 : zend_error(E_WARNING, "Failed to decode _POST array");
539 0 : PG(request_decoding_error) = 1;
540 0 : zend_hash_clean(Z_ARRVAL_P(array_ptr));
541 : }
542 : }
543 22 : return;
544 : } else {
545 19 : sapi_handle_post(array_ptr TSRMLS_CC);
546 : }
547 : }
548 :
549 17037 : if (arg == PARSE_GET) { /* GET data */
550 9 : c_var = SG(request_info).query_string;
551 18 : if (c_var && *c_var) {
552 9 : res = (char *) estrdup(c_var);
553 9 : free_buffer = 1;
554 : } else {
555 0 : free_buffer = 0;
556 : }
557 9 : conv = UG(request_encoding_conv);
558 17028 : } else if (arg == PARSE_COOKIE) { /* Cookie data */
559 16981 : c_var = SG(request_info).cookie_data;
560 16995 : if (c_var && *c_var) {
561 14 : res = (char *) estrdup(c_var);
562 14 : free_buffer = 1;
563 : } else {
564 16967 : free_buffer = 0;
565 : }
566 16981 : conv = UG(request_encoding_conv);
567 47 : } else if (arg == PARSE_STRING) { /* String data */
568 28 : res = str;
569 28 : free_buffer = 1;
570 28 : conv = ZEND_U_CONVERTER(UG(runtime_encoding_conv));
571 : }
572 :
573 17037 : if (!res) {
574 16986 : return;
575 : }
576 :
577 51 : switch (arg) {
578 : case PARSE_GET:
579 : case PARSE_STRING:
580 37 : separator = (char *) estrdup(PG(arg_separator).input);
581 37 : break;
582 : case PARSE_COOKIE:
583 14 : separator = ";\0";
584 : break;
585 : }
586 :
587 51 : var = php_strtok_r(res, separator, &strtok_buf);
588 :
589 235 : while (var) {
590 : int var_len, val_len;
591 :
592 133 : val = strchr(var, '=');
593 :
594 133 : if (arg == PARSE_COOKIE) {
595 : /* Remove leading spaces from cookie names, needed for multi-cookie header where ; can be followed by a space */
596 102 : while (isspace(*var)) {
597 10 : var++;
598 : }
599 46 : if (var == val || *var == '\0') {
600 : goto next_var;
601 : }
602 : }
603 :
604 133 : if (val) {
605 131 : *val++ = '\0';
606 : }
607 133 : var_len = strlen(var);
608 133 : php_url_decode(var, var_len);
609 :
610 133 : if (val) { /* have a value */
611 131 : val_len = php_url_decode(val, strlen(val));
612 : } else {
613 2 : val = "";
614 2 : val_len = 0;
615 : }
616 :
617 133 : if (php_register_variable_with_conv(conv, var, var_len, val, val_len, array_ptr, arg TSRMLS_CC) == FAILURE) {
618 0 : zend_error(E_WARNING, "Failed to decode %s array", arg_names[arg]);
619 0 : PG(request_decoding_error) = 1;
620 0 : zend_hash_clean(Z_ARRVAL_P(array_ptr));
621 0 : break;
622 : }
623 :
624 133 : next_var:
625 133 : var = php_strtok_r(NULL, separator, &strtok_buf);
626 : }
627 :
628 51 : if (arg != PARSE_COOKIE) {
629 37 : efree(separator);
630 : }
631 :
632 51 : if (free_buffer) {
633 51 : efree(res);
634 : }
635 : }
636 :
637 : void _php_import_environment_variables(zval *array_ptr TSRMLS_DC)
638 18051 : {
639 : char buf[128];
640 18051 : char **env, *p, *t = buf;
641 18051 : size_t alloc_size = sizeof(buf);
642 : unsigned long nlen; /* ptrdiff_t is not portable */
643 :
644 833822 : for (env = environ; env != NULL && *env != NULL; env++) {
645 815771 : p = strchr(*env, '=');
646 815771 : if (!p) { /* malformed entry? */
647 0 : continue;
648 : }
649 815771 : nlen = p - *env;
650 815771 : if (nlen >= alloc_size) {
651 0 : alloc_size = nlen + 64;
652 0 : t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size));
653 : }
654 815771 : memcpy(t, *env, nlen);
655 815771 : t[nlen] = '\0';
656 815771 : php_register_variable(t, p + 1, array_ptr TSRMLS_CC);
657 : }
658 18051 : if (t != buf && t != NULL) {
659 0 : efree(t);
660 : }
661 18051 : }
662 :
663 : /* {{{ php_build_argv
664 : */
665 : static void php_build_argv(char *s, zval *track_vars_array TSRMLS_DC)
666 17087 : {
667 : zval *arr, *argc, *tmp;
668 17087 : int count = 0;
669 : char *ss, *space;
670 :
671 17087 : if (!(SG(request_info).argc || track_vars_array)) {
672 199 : return;
673 : }
674 :
675 16888 : ALLOC_INIT_ZVAL(arr);
676 16888 : array_init(arr);
677 :
678 : /* Prepare argv */
679 16888 : if (SG(request_info).argc) { /* are we in cli sapi? */
680 : int i;
681 33635 : for (i = 0; i < SG(request_info).argc; i++) {
682 16844 : ALLOC_ZVAL(tmp);
683 : /* leave args as binary, since the encoding is not known */
684 16844 : ZVAL_STRING(tmp, SG(request_info).argv[i], 1);
685 16844 : INIT_PZVAL(tmp);
686 16844 : if (zend_hash_next_index_insert(Z_ARRVAL_P(arr), &tmp, sizeof(zval *), NULL) == FAILURE) {
687 0 : if (Z_TYPE_P(tmp) == IS_STRING) {
688 0 : efree(Z_STRVAL_P(tmp));
689 : }
690 : }
691 : }
692 97 : } else if (s && *s) {
693 2 : ss = s;
694 10 : while (ss) {
695 6 : space = strchr(ss, '+');
696 6 : if (space) {
697 4 : *space = '\0';
698 : }
699 : /* auto-type */
700 6 : ALLOC_ZVAL(tmp);
701 : /* UTODO
702 : * use UG(request_encoding) here. This also means that we need to clean out
703 : * and re-arm $_SERVER and clean out $argv on request_set_encoding()
704 : */
705 6 : ZVAL_RT_STRING(tmp, ss, 1);
706 6 : INIT_PZVAL(tmp);
707 6 : count++;
708 6 : if (zend_hash_next_index_insert(Z_ARRVAL_P(arr), &tmp, sizeof(zval *), NULL) == FAILURE) {
709 0 : efree(Z_STRVAL_P(tmp));
710 : }
711 6 : if (space) {
712 4 : *space = '+';
713 4 : ss = space + 1;
714 : } else {
715 2 : ss = space;
716 : }
717 : }
718 : }
719 :
720 : /* prepare argc */
721 16888 : ALLOC_INIT_ZVAL(argc);
722 16888 : if (SG(request_info).argc) {
723 16791 : Z_LVAL_P(argc) = SG(request_info).argc;
724 : } else {
725 97 : Z_LVAL_P(argc) = count;
726 : }
727 16888 : Z_TYPE_P(argc) = IS_LONG;
728 :
729 16888 : if (SG(request_info).argc) {
730 16791 : Z_ADDREF_P(arr);
731 16791 : Z_ADDREF_P(argc);
732 16791 : zend_ascii_hash_update(&EG(symbol_table), "argv", sizeof("argv"), &arr, sizeof(zval *), NULL);
733 16791 : zend_ascii_hash_add(&EG(symbol_table), "argc", sizeof("argc"), &argc, sizeof(zval *), NULL);
734 : }
735 16888 : if (track_vars_array) {
736 97 : Z_ADDREF_P(arr);
737 97 : Z_ADDREF_P(argc);
738 97 : zend_ascii_hash_update(Z_ARRVAL_P(track_vars_array), "argv", sizeof("argv"), &arr, sizeof(zval *), NULL);
739 97 : zend_ascii_hash_update(Z_ARRVAL_P(track_vars_array), "argc", sizeof("argc"), &argc, sizeof(zval *), NULL);
740 : }
741 16888 : zval_ptr_dtor(&arr);
742 16888 : zval_ptr_dtor(&argc);
743 : }
744 : /* }}} */
745 :
746 : /* {{{ php_handle_special_queries
747 : */
748 : PHPAPI int php_handle_special_queries(TSRMLS_D)
749 16913 : {
750 16913 : if (PG(expose_php) && SG(request_info).query_string && SG(request_info).query_string[0] == '=') {
751 0 : if (php_info_logos(SG(request_info).query_string + 1 TSRMLS_CC)) {
752 0 : return 1;
753 0 : } else if (!strcmp(SG(request_info).query_string + 1, PHP_CREDITS_GUID)) {
754 0 : php_print_credits(PHP_CREDITS_ALL TSRMLS_CC);
755 0 : return 1;
756 : }
757 : }
758 16913 : return 0;
759 : }
760 : /* }}} */
761 :
762 : /* {{{ php_register_server_variables
763 : */
764 : static inline void php_register_server_variables(TSRMLS_D)
765 16735 : {
766 16735 : zval *array_ptr = NULL;
767 :
768 16735 : ALLOC_ZVAL(array_ptr);
769 16735 : array_init(array_ptr);
770 16735 : INIT_PZVAL(array_ptr);
771 16735 : if (PG(http_globals)[TRACK_VARS_SERVER]) {
772 0 : zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]);
773 : }
774 16735 : PG(http_globals)[TRACK_VARS_SERVER] = array_ptr;
775 :
776 : /* Server variables */
777 16735 : if (sapi_module.register_server_variables) {
778 16735 : sapi_module.register_server_variables(array_ptr TSRMLS_CC);
779 : }
780 :
781 : /* PHP Authentication support */
782 16735 : if (SG(request_info).auth_user) {
783 0 : php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, array_ptr TSRMLS_CC);
784 : }
785 16735 : if (SG(request_info).auth_password) {
786 0 : php_register_variable("PHP_AUTH_PW", SG(request_info).auth_password, array_ptr TSRMLS_CC);
787 : }
788 16735 : if (SG(request_info).auth_digest) {
789 0 : php_register_variable("PHP_AUTH_DIGEST", SG(request_info).auth_digest, array_ptr TSRMLS_CC);
790 : }
791 : /* store request init time */
792 : {
793 : zval new_entry;
794 16735 : Z_TYPE(new_entry) = IS_LONG;
795 16735 : Z_LVAL(new_entry) = sapi_get_request_time(TSRMLS_C);
796 16735 : php_register_variable_ex("REQUEST_TIME", &new_entry, array_ptr TSRMLS_CC);
797 : }
798 16735 : }
799 : /* }}} */
800 :
801 : /* {{{ php_autoglobal_merge
802 : */
803 : static void php_autoglobal_merge(HashTable *dest, HashTable *src TSRMLS_DC)
804 15 : {
805 : zval **src_entry, **dest_entry;
806 : zstr string_key;
807 : uint string_key_len;
808 : ulong num_key;
809 : HashPosition pos;
810 : int key_type;
811 :
812 15 : zend_hash_internal_pointer_reset_ex(src, &pos);
813 58 : while (zend_hash_get_current_data_ex(src, (void **)&src_entry, &pos) == SUCCESS) {
814 28 : key_type = zend_hash_get_current_key_ex(src, &string_key, &string_key_len, &num_key, 0, &pos);
815 56 : if (Z_TYPE_PP(src_entry) != IS_ARRAY
816 : || ((key_type == HASH_KEY_IS_UNICODE || key_type == HASH_KEY_IS_STRING) && zend_u_hash_find(dest, key_type, string_key, string_key_len, (void **) &dest_entry) != SUCCESS)
817 : || (key_type == HASH_KEY_IS_LONG && zend_hash_index_find(dest, num_key, (void **)&dest_entry) != SUCCESS)
818 : || Z_TYPE_PP(dest_entry) != IS_ARRAY
819 : ) {
820 28 : Z_ADDREF_PP(src_entry);
821 55 : if (key_type == HASH_KEY_IS_STRING || key_type == HASH_KEY_IS_UNICODE) {
822 27 : zend_u_hash_update(dest, key_type, string_key, string_key_len, src_entry, sizeof(zval *), NULL);
823 : } else {
824 1 : zend_hash_index_update(dest, num_key, src_entry, sizeof(zval *), NULL);
825 : }
826 : } else {
827 0 : SEPARATE_ZVAL(dest_entry);
828 0 : php_autoglobal_merge(Z_ARRVAL_PP(dest_entry), Z_ARRVAL_PP(src_entry) TSRMLS_CC);
829 : }
830 28 : zend_hash_move_forward_ex(src, &pos);
831 : }
832 15 : }
833 : /* }}} */
834 :
835 : static int php_decode_raw_var_array(HashTable *raw_array, zval *track_array TSRMLS_DC)
836 43 : {
837 : zstr raw_var;
838 : uint raw_var_len;
839 : zval **raw_value;
840 : zstr var, value;
841 : int var_len, value_len;
842 : ulong num_index;
843 43 : zend_uchar type = IS_UNICODE;
844 43 : UConverter *conv = UG(request_encoding_conv);
845 :
846 43 : if (conv == NULL) {
847 0 : type = IS_STRING;
848 : }
849 :
850 43 : for (zend_hash_internal_pointer_reset(raw_array);
851 302 : zend_hash_get_current_data(raw_array, (void **)&raw_value) == SUCCESS;
852 : zend_hash_move_forward(raw_array)
853 216 : ) {
854 216 : zend_hash_get_current_key_ex(raw_array, &raw_var, &raw_var_len, &num_index, 0, NULL);
855 :
856 216 : if (type == IS_UNICODE) {
857 216 : var.u = value.u = NULL;
858 :
859 216 : if (zend_string_to_unicode(conv, &var.u, &var_len, raw_var.s, raw_var_len TSRMLS_CC) == FAILURE) {
860 0 : return FAILURE;
861 : }
862 :
863 216 : if (Z_TYPE_PP(raw_value) == IS_STRING) {
864 138 : if (zend_string_to_unicode(conv, &value.u, &value_len, Z_STRVAL_PP(raw_value), Z_STRLEN_PP(raw_value) TSRMLS_CC) == FAILURE) {
865 0 : efree(var.u);
866 0 : return FAILURE;
867 : }
868 :
869 : /* UTODO add input filtering */
870 138 : php_register_variable_safe(IS_UNICODE, var, value, value_len, track_array TSRMLS_CC);
871 138 : efree(value.u);
872 : } else {
873 78 : php_u_register_variable_ex(var.u, *raw_value, track_array TSRMLS_CC);
874 : }
875 :
876 216 : efree(var.u);
877 : } else {
878 0 : var.s = raw_var.s;
879 0 : var_len = raw_var_len;
880 0 : if (Z_TYPE_PP(raw_value) == IS_STRING) {
881 0 : value.s = Z_STRVAL_PP(raw_value);
882 0 : value_len = Z_STRLEN_PP(raw_value);
883 :
884 : /* UTODO add input filtering */
885 0 : php_register_variable_safe(IS_STRING, var, value, value_len, track_array TSRMLS_CC);
886 : } else {
887 0 : php_register_variable_ex(var.s, *raw_value, track_array TSRMLS_CC);
888 : }
889 : }
890 : }
891 :
892 43 : return SUCCESS;
893 : }
894 :
895 : static zend_bool php_auto_globals_create_server(char *name, uint name_len TSRMLS_DC);
896 : static zend_bool php_auto_globals_create_env(char *name, uint name_len TSRMLS_DC);
897 : static zend_bool php_auto_globals_create_request(char *name, uint name_len TSRMLS_DC);
898 : static zend_bool php_auto_globals_decode_get(char *name, uint name_len TSRMLS_DC);
899 : static zend_bool php_auto_globals_decode_post(char *name, uint name_len TSRMLS_DC);
900 : static zend_bool php_auto_globals_decode_files(char *name, uint name_len TSRMLS_DC);
901 :
902 : /* {{{ php_hash_environment
903 : */
904 : int php_hash_environment(TSRMLS_D)
905 16993 : {
906 : char *p;
907 16993 : unsigned char _gpc_flags[5] = {0, 0, 0, 0, 0};
908 16993 : zend_bool jit_initialization = PG(auto_globals_jit);
909 : struct auto_global_record {
910 : char *name;
911 : uint name_len;
912 : zend_bool jit_initialization;
913 : } auto_global_records[] = {
914 : { "_POST", sizeof("_POST"), 0 },
915 : { "_GET", sizeof("_GET"), 0 },
916 : { "_COOKIE", sizeof("_COOKIE"), 0 },
917 : { "_SERVER", sizeof("_SERVER"), 1 },
918 : { "_ENV", sizeof("_ENV"), 1 },
919 : { "_FILES", sizeof("_FILES"), 0 }
920 16993 : };
921 16993 : size_t num_track_vars = sizeof(auto_global_records)/sizeof(struct auto_global_record);
922 : size_t i;
923 :
924 : /* jit_initialization = 0; */
925 118951 : for (i=0; i<num_track_vars; i++) {
926 101958 : PG(http_globals)[i] = NULL;
927 : }
928 :
929 101930 : for (p=PG(variables_order); p && *p; p++) {
930 84937 : switch(*p) {
931 : case 'c':
932 : case 'C':
933 16984 : if (!_gpc_flags[1]) {
934 16984 : sapi_module.treat_data(PARSE_COOKIE, NULL, NULL TSRMLS_CC); /* Cookie Data */
935 16984 : _gpc_flags[1] = 1;
936 : }
937 16984 : break;
938 :
939 : case 'e':
940 : case 'E':
941 16981 : if (!jit_initialization && !_gpc_flags[3]) {
942 0 : zend_auto_global_disable_jit("_ENV", sizeof("_ENV")-1 TSRMLS_CC);
943 0 : php_auto_globals_create_env("_ENV", sizeof("_ENV")-1 TSRMLS_CC);
944 0 : _gpc_flags[3] = 1;
945 : }
946 16981 : break;
947 :
948 : case 's':
949 : case 'S':
950 16988 : if (!jit_initialization && !_gpc_flags[4]) {
951 0 : zend_auto_global_disable_jit("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
952 0 : php_register_server_variables(TSRMLS_C);
953 0 : _gpc_flags[4] = 1;
954 : }
955 : break;
956 : }
957 : }
958 :
959 : /* argv/argc support */
960 16993 : if (PG(register_argc_argv)) {
961 16990 : php_build_argv(SG(request_info).query_string, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
962 : }
963 :
964 118951 : for (i=0; i<num_track_vars; i++) {
965 101958 : if (jit_initialization && auto_global_records[i].jit_initialization) {
966 33986 : continue;
967 : }
968 67972 : if (!PG(http_globals)[i]) {
969 50988 : ALLOC_ZVAL(PG(http_globals)[i]);
970 50988 : array_init(PG(http_globals)[i]);
971 50988 : INIT_PZVAL(PG(http_globals)[i]);
972 : }
973 :
974 67972 : Z_ADDREF_P(PG(http_globals)[i]);
975 67972 : zend_ascii_hash_update(&EG(symbol_table), auto_global_records[i].name, auto_global_records[i].name_len, &PG(http_globals)[i], sizeof(zval *), NULL);
976 : }
977 :
978 16993 : return SUCCESS;
979 : }
980 : /* }}} */
981 :
982 : static zend_bool php_auto_globals_decode_get(char *name, uint name_len TSRMLS_DC)
983 9 : {
984 9 : sapi_module.treat_data(PARSE_GET, NULL, NULL TSRMLS_CC); /* GET Data */
985 9 : zend_ascii_hash_update(&EG(symbol_table), name, name_len + 1, &PG(http_globals)[TRACK_VARS_GET], sizeof(zval *), NULL);
986 9 : Z_ADDREF_P(PG(http_globals)[TRACK_VARS_GET]);
987 9 : return 0;
988 : }
989 :
990 : static zend_bool php_auto_globals_decode_post(char *name, uint name_len TSRMLS_DC)
991 43 : {
992 43 : if (SG(request_info).request_method && !strcasecmp(SG(request_info).request_method, "POST")) {
993 41 : sapi_module.treat_data(PARSE_POST, NULL, NULL TSRMLS_CC); /* POST Data */
994 41 : zend_ascii_hash_update(&EG(symbol_table), name, name_len + 1, &PG(http_globals)[TRACK_VARS_POST], sizeof(zval *), NULL);
995 41 : Z_ADDREF_P(PG(http_globals)[TRACK_VARS_POST]);
996 : }
997 43 : return 0;
998 : }
999 :
1000 : static zend_bool php_auto_globals_decode_files(char *name, uint name_len TSRMLS_DC)
1001 28 : {
1002 28 : if (PG(http_globals)[TRACK_VARS_FILES]) {
1003 28 : zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_FILES]);
1004 : }
1005 28 : ALLOC_ZVAL(PG(http_globals)[TRACK_VARS_FILES]);
1006 28 : array_init(PG(http_globals)[TRACK_VARS_FILES]);
1007 28 : INIT_PZVAL(PG(http_globals)[TRACK_VARS_FILES]);
1008 28 : zend_ascii_hash_update(&EG(symbol_table), name, name_len + 1, &PG(http_globals)[TRACK_VARS_FILES], sizeof(zval *), NULL);
1009 28 : Z_ADDREF_P(PG(http_globals)[TRACK_VARS_FILES]);
1010 :
1011 28 : if (SG(request_info).post_entry &&
1012 : SG(request_info).post_entry->post_handler == rfc1867_post_handler) {
1013 :
1014 27 : if (SG(rfc1867_files_vars) == NULL) {
1015 19 : sapi_handle_post(NULL TSRMLS_CC);
1016 : }
1017 27 : if (SG(rfc1867_files_vars) != NULL) {
1018 24 : PG(request_decoding_error) = 0;
1019 24 : if (php_decode_raw_var_array(SG(rfc1867_files_vars), PG(http_globals)[TRACK_VARS_FILES] TSRMLS_CC) == FAILURE) {
1020 0 : zend_error(E_WARNING, "Failed to decode _FILES array");
1021 0 : PG(request_decoding_error) = 1;
1022 0 : zend_hash_clean(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_FILES]));
1023 : }
1024 : }
1025 : }
1026 28 : return 0;
1027 : }
1028 :
1029 : static zend_bool php_auto_globals_create_server(char *name, uint name_len TSRMLS_DC)
1030 16737 : {
1031 33472 : if (PG(variables_order) && (strchr(PG(variables_order),'S') || strchr(PG(variables_order),'s'))) {
1032 16735 : php_register_server_variables(TSRMLS_C);
1033 :
1034 16735 : if (PG(register_argc_argv)) {
1035 16733 : if (SG(request_info).argc) {
1036 : zval **argc, **argv;
1037 :
1038 16636 : if (zend_ascii_hash_find(&EG(symbol_table), "argc", sizeof("argc"), (void**)&argc) == SUCCESS &&
1039 : zend_ascii_hash_find(&EG(symbol_table), "argv", sizeof("argv"), (void**)&argv) == SUCCESS
1040 : ) {
1041 16636 : Z_ADDREF_PP(argc);
1042 16636 : Z_ADDREF_PP(argv);
1043 16636 : zend_ascii_hash_update(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv"), argv, sizeof(zval *), NULL);
1044 16636 : zend_ascii_hash_update(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "argc", sizeof("argc"), argc, sizeof(zval *), NULL);
1045 : }
1046 : } else {
1047 97 : php_build_argv(SG(request_info).query_string, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
1048 : }
1049 : }
1050 :
1051 : } else {
1052 2 : zval *server_vars=NULL;
1053 2 : ALLOC_ZVAL(server_vars);
1054 2 : array_init(server_vars);
1055 2 : INIT_PZVAL(server_vars);
1056 2 : if (PG(http_globals)[TRACK_VARS_SERVER]) {
1057 0 : zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_SERVER]);
1058 : }
1059 2 : PG(http_globals)[TRACK_VARS_SERVER] = server_vars;
1060 : }
1061 :
1062 16737 : zend_ascii_hash_update(&EG(symbol_table), name, name_len + 1, &PG(http_globals)[TRACK_VARS_SERVER], sizeof(zval *), NULL);
1063 16737 : Z_ADDREF_P(PG(http_globals)[TRACK_VARS_SERVER]);
1064 :
1065 16737 : return 0; /* don't rearm */
1066 : }
1067 :
1068 : static zend_bool php_auto_globals_create_env(char *name, uint name_len TSRMLS_DC)
1069 1317 : {
1070 1317 : zval *env_vars = NULL;
1071 1317 : ALLOC_ZVAL(env_vars);
1072 1317 : array_init(env_vars);
1073 1317 : INIT_PZVAL(env_vars);
1074 1317 : if (PG(http_globals)[TRACK_VARS_ENV]) {
1075 0 : zval_ptr_dtor(&PG(http_globals)[TRACK_VARS_ENV]);
1076 : }
1077 1317 : PG(http_globals)[TRACK_VARS_ENV] = env_vars;
1078 :
1079 1317 : if (PG(variables_order) && (strchr(PG(variables_order),'E') || strchr(PG(variables_order),'e'))) {
1080 1316 : php_import_environment_variables(PG(http_globals)[TRACK_VARS_ENV] TSRMLS_CC);
1081 : }
1082 :
1083 1317 : zend_ascii_hash_update(&EG(symbol_table), name, name_len + 1, &PG(http_globals)[TRACK_VARS_ENV], sizeof(zval *), NULL);
1084 1317 : Z_ADDREF_P(PG(http_globals)[TRACK_VARS_ENV]);
1085 :
1086 1317 : return 0; /* don't rearm */
1087 : }
1088 :
1089 : static zend_bool php_auto_globals_create_request(char *name, uint name_len TSRMLS_DC)
1090 5 : {
1091 : zval *form_variables;
1092 5 : unsigned char _gpc_flags[3] = {0, 0, 0};
1093 : char *p;
1094 :
1095 5 : ALLOC_ZVAL(form_variables);
1096 5 : array_init(form_variables);
1097 5 : INIT_PZVAL(form_variables);
1098 :
1099 5 : if (PG(request_order) != NULL) {
1100 0 : p = PG(request_order);
1101 : } else {
1102 5 : p = PG(variables_order);
1103 : }
1104 :
1105 28 : for (; p && *p; p++) {
1106 23 : switch (*p) {
1107 : case 'g':
1108 : case 'G':
1109 5 : if (!_gpc_flags[0]) {
1110 5 : zend_u_is_auto_global_ex(IS_STRING, ZSTR("_GET"), sizeof("_GET")-1, 1, NULL TSRMLS_CC);
1111 5 : php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]) TSRMLS_CC);
1112 5 : _gpc_flags[0] = 1;
1113 : }
1114 5 : break;
1115 : case 'p':
1116 : case 'P':
1117 5 : if (!_gpc_flags[1]) {
1118 5 : zend_u_is_auto_global_ex(IS_STRING, ZSTR("_POST"), sizeof("_POST")-1, 1, NULL TSRMLS_CC);
1119 5 : php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]) TSRMLS_CC);
1120 5 : _gpc_flags[1] = 1;
1121 : }
1122 5 : break;
1123 : case 'c':
1124 : case 'C':
1125 5 : if (!_gpc_flags[2]) {
1126 5 : php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]) TSRMLS_CC);
1127 5 : _gpc_flags[2] = 1;
1128 : }
1129 : break;
1130 : }
1131 : }
1132 :
1133 5 : zend_ascii_hash_update(&EG(symbol_table), "_REQUEST", sizeof("_REQUEST"), &form_variables, sizeof(zval *), NULL);
1134 5 : return 0;
1135 : }
1136 :
1137 : void php_startup_auto_globals(TSRMLS_D)
1138 17007 : {
1139 17007 : zend_register_auto_global_ex("_GET", sizeof("_GET")-1, php_auto_globals_decode_get, 1 TSRMLS_CC);
1140 17007 : zend_register_auto_global_ex("_POST", sizeof("_POST")-1, php_auto_globals_decode_post, 1 TSRMLS_CC);
1141 17007 : zend_register_auto_global("_COOKIE", sizeof("_COOKIE")-1, NULL TSRMLS_CC);
1142 17007 : zend_register_auto_global("_SERVER", sizeof("_SERVER")-1, php_auto_globals_create_server TSRMLS_CC);
1143 17007 : zend_register_auto_global("_ENV", sizeof("_ENV")-1, php_auto_globals_create_env TSRMLS_CC);
1144 17007 : zend_register_auto_global_ex("_REQUEST", sizeof("_REQUEST")-1, php_auto_globals_create_request, 1 TSRMLS_CC);
1145 17007 : zend_register_auto_global_ex("_FILES", sizeof("_FILES")-1, php_auto_globals_decode_files, 1 TSRMLS_CC);
1146 17007 : }
1147 :
1148 : /*
1149 : * Local variables:
1150 : * tab-width: 4
1151 : * c-basic-offset: 4
1152 : * End:
1153 : * vim600: sw=4 ts=4 fdm=marker
1154 : * vim<600: sw=4 ts=4
1155 : */
|