while (1) {
if (is_array) {
- char *escaped_index;
+ char *escaped_index = NULL, *index_s;
+ int new_idx_len = 0;
+
+ ip++;
+ index_s = ip;
+ if (isspace(*ip)) {
+ ip++;
+ }
+ if (*ip==']') {
+ index_s = NULL;
+ } else {
+ ip = strchr(ip, ']');
+ if (!ip) {
+ /* PHP variables cannot contain '[' in their names, so we replace the character with a '_' */
+ *(index_s - 1) = '_';
+ index_len = var_len = strlen(var);
+ goto plain_var;
+ return;
+ }
+ *ip = 0;
+ new_idx_len = strlen(index_s);
+ }
if (!index) {
MAKE_STD_ZVAL(gpc_element);
}
symtable1 = Z_ARRVAL_PP(gpc_element_p);
/* ip pointed to the '[' character, now obtain the key */
- index = ++ip;
- index_len = 0;
- if (*ip=='\n' || *ip=='\r' || *ip=='\t' || *ip==' ') {
- ip++;
- }
- if (*ip==']') {
- index = NULL;
- } else {
- ip = strchr(ip, ']');
- if (!ip) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Missing ] in %s variable", var);
- return;
- }
- *ip = 0;
- index_len = strlen(index);
- }
+ index = index_s;
+ index_len = new_idx_len;
+
ip++;
if (*ip=='[') {
is_array = 1;
is_array = 0;
}
} else {
+plain_var:
MAKE_STD_ZVAL(gpc_element);
gpc_element->value = val->value;
Z_TYPE_P(gpc_element) = Z_TYPE_P(val);
/* done? */
while (index) {
-
+
while (*index == ' ' || *index == '\r' || *index == '\n' || *index=='\t') {
index++;
}
* ends in [.*]
* start_arr is set to point to 1st [
*/
- is_arr_upload = (start_arr = strchr(param,'[')) &&
- (param[strlen(param)-1] == ']');
+ is_arr_upload = (start_arr = strchr(param,'[')) && (param[strlen(param)-1] == ']');
+ /* handle unterminated [ */
+ if (!is_arr_upload && start_arr) {
+ *start_arr = '_';
+ }
if (is_arr_upload) {
array_len = strlen(start_arr);