Skip to content

HTTPS clone URL

Subversion checkout URL

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