laruence

max_input_vars

Feb 8th, 2012
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.84 KB | None | 0 0
  1. Index: trunk/ext/standard/basic_functions.c
  2. ===================================================================
  3. --- trunk/ext/standard/basic_functions.c    (revision 323122)
  4. +++ trunk/ext/standard/basic_functions.c    (working copy)
  5. @@ -854,6 +854,9 @@
  6.      ZEND_ARG_INFO(0, scanner_mode)
  7.  ZEND_END_ARG_INFO()
  8.  
  9. +ZEND_BEGIN_ARG_INFO(arginfo_input_vars_count, 0)
  10. +ZEND_END_ARG_INFO()
  11. +
  12.  #if ZEND_DEBUG
  13.  ZEND_BEGIN_ARG_INFO(arginfo_config_get_hash, 0)
  14.  ZEND_END_ARG_INFO()
  15. @@ -3019,6 +3022,7 @@
  16.     PHP_FE(is_uploaded_file,                                                arginfo_is_uploaded_file)
  17.     PHP_FE(move_uploaded_file,                                              arginfo_move_uploaded_file)
  18.  
  19. +   PHP_FE(input_vars_count,                                            arginfo_input_vars_count)
  20.     /* functions from dns.c */
  21.     PHP_FE(gethostbyaddr,                                                   arginfo_gethostbyaddr)
  22.     PHP_FE(gethostbyname,                                                   arginfo_gethostbyname)
  23. @@ -5832,6 +5836,14 @@
  24.  }
  25.  /* }}} */
  26.  
  27. +/* {{{ proto int input_vars_count(void)
  28. +   */
  29. +PHP_FUNCTION(input_vars_count)
  30. +{
  31. +   RETURN_LONG(PG(input_vars_count));
  32. +}
  33. +/* }}} */
  34. +
  35.  /* {{{ php_simple_ini_parser_cb
  36.   */
  37.  static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_type, zval *arr TSRMLS_DC)
  38. Index: trunk/ext/standard/basic_functions.h
  39. ===================================================================
  40. --- trunk/ext/standard/basic_functions.h    (revision 323122)
  41. +++ trunk/ext/standard/basic_functions.h    (working copy)
  42. @@ -124,6 +124,8 @@
  43.  PHP_FUNCTION(is_uploaded_file);
  44.  PHP_FUNCTION(move_uploaded_file);
  45.  
  46. +PHP_FUNCTION(input_vars_count);
  47. +
  48.  /* From the INI parser */
  49.  PHP_FUNCTION(parse_ini_file);
  50.  PHP_FUNCTION(parse_ini_string);
  51. Index: trunk/main/php_globals.h
  52. ===================================================================
  53. --- trunk/main/php_globals.h    (revision 323122)
  54. +++ trunk/main/php_globals.h    (working copy)
  55. @@ -147,6 +147,7 @@
  56.  #endif
  57.     long max_input_nesting_level;
  58.     long max_input_vars;
  59. +   long input_vars_count;
  60.     zend_bool in_user_include;
  61.  
  62.     char *user_ini_filename;
  63. Index: trunk/main/rfc1867.c
  64. ===================================================================
  65. --- trunk/main/rfc1867.c    (revision 323122)
  66. +++ trunk/main/rfc1867.c    (working copy)
  67. @@ -861,6 +861,15 @@
  68.                     }
  69.                 }
  70.  
  71. +               if (++PG(input_vars_count) > PG(max_input_vars)) {
  72. +                   if (php_rfc1867_callback != NULL) {
  73. +                       goto call_rfc1867_callback;
  74. +                   }
  75. +                   continue;
  76. +               } else if (PG(input_vars_count) == PG(max_input_vars)) {
  77. +                   php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variables reached %ld. To increase the limit change max_input_vars in php.ini.", PG(max_input_vars));
  78. +               }
  79. +
  80.                 if (sapi_module.input_filter(PARSE_POST, param, &value, value_len, &new_val_len TSRMLS_CC)) {
  81.                     if (php_rfc1867_callback != NULL) {
  82.                         multipart_event_formdata event_formdata;
  83. @@ -880,14 +889,17 @@
  84.                     }
  85.                     safe_php_register_variable(param, value, new_val_len, array_ptr, 0 TSRMLS_CC);
  86.                 } else if (php_rfc1867_callback != NULL) {
  87. -                   multipart_event_formdata event_formdata;
  88. +call_rfc1867_callback:
  89. +                   {
  90. +                       multipart_event_formdata event_formdata;
  91.  
  92. -                   event_formdata.post_bytes_processed = SG(read_post_bytes);
  93. -                   event_formdata.name = param;
  94. -                   event_formdata.value = &value;
  95. -                   event_formdata.length = value_len;
  96. -                   event_formdata.newlength = NULL;
  97. -                   php_rfc1867_callback(MULTIPART_EVENT_FORMDATA, &event_formdata, &event_extra_data TSRMLS_CC);
  98. +                       event_formdata.post_bytes_processed = SG(read_post_bytes);
  99. +                       event_formdata.name = param;
  100. +                       event_formdata.value = &value;
  101. +                       event_formdata.length = value_len;
  102. +                       event_formdata.newlength = NULL;
  103. +                       php_rfc1867_callback(MULTIPART_EVENT_FORMDATA, &event_formdata, &event_extra_data TSRMLS_CC);
  104. +                   }
  105.                 }
  106.  
  107.                 if (!strcasecmp(param, "MAX_FILE_SIZE")) {
  108. Index: trunk/main/php_variables.c
  109. ===================================================================
  110. --- trunk/main/php_variables.c  (revision 323123)
  111. +++ trunk/main/php_variables.c  (working copy)
  112. @@ -77,7 +77,6 @@
  113.         return;
  114.     }
  115.  
  116. -
  117.     /* ignore leading spaces in the variable name */
  118.     while (*var_name && *var_name==' ') {
  119.         var_name++;
  120. @@ -103,7 +102,7 @@
  121.     }
  122.     var_len = p - var;
  123.  
  124. -   if (var_len==0) { /* empty variable name, or variable name with a space in it */
  125. +   if (var_len == 0) { /* empty variable name, or variable name with a space in it */
  126.         zval_dtor(val);
  127.         free_alloca(var_orig, use_heap);
  128.         return;
  129. @@ -127,7 +126,7 @@
  130.             char *index_s;
  131.             int new_idx_len = 0;
  132.  
  133. -           if(++nest_level > PG(max_input_nesting_level)) {
  134. +           if (++nest_level > PG(max_input_nesting_level)) {
  135.                 HashTable *ht;
  136.                 /* too many levels of nesting */
  137.  
  138. @@ -152,7 +151,7 @@
  139.             if (isspace(*ip)) {
  140.                 ip++;
  141.             }
  142. -           if (*ip==']') {
  143. +           if (*ip == ']') {
  144.                 index_s = NULL;
  145.             } else {
  146.                 ip = strchr(ip, ']');
  147. @@ -183,18 +182,9 @@
  148.             } else {
  149.                 if (zend_symtable_find(symtable1, index, index_len + 1, (void **) &gpc_element_p) == FAILURE
  150.                     || Z_TYPE_PP(gpc_element_p) != IS_ARRAY) {
  151. -                   if (zend_hash_num_elements(symtable1) <= PG(max_input_vars)) {
  152. -                       if (zend_hash_num_elements(symtable1) == PG(max_input_vars)) {
  153. -                           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));
  154. -                       }
  155. -                       MAKE_STD_ZVAL(gpc_element);
  156. -                       array_init(gpc_element);
  157. -                       zend_symtable_update(symtable1, index, index_len + 1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
  158. -                   } else {
  159. -                       zval_dtor(val);
  160. -                       free_alloca(var_orig, use_heap);
  161. -                       return;
  162. -                   }
  163. +                   MAKE_STD_ZVAL(gpc_element);
  164. +                   array_init(gpc_element);
  165. +                   zend_symtable_update(symtable1, index, index_len + 1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
  166.                 }
  167.             }
  168.             symtable1 = Z_ARRVAL_PP(gpc_element_p);
  169. @@ -231,14 +221,7 @@
  170.                 zend_symtable_exists(symtable1, index, index_len + 1)) {
  171.                 zval_ptr_dtor(&gpc_element);
  172.             } else {
  173. -               if (zend_hash_num_elements(symtable1) <= PG(max_input_vars)) {
  174. -                   if (zend_hash_num_elements(symtable1) == PG(max_input_vars)) {
  175. -                       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));
  176. -                   }
  177. -                   zend_symtable_update(symtable1, index, index_len + 1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
  178. -               } else {
  179. -                   zval_ptr_dtor(&gpc_element);
  180. -               }
  181. +               zend_symtable_update(symtable1, index, index_len + 1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p);
  182.             }
  183.         }
  184.     }
  185. @@ -262,6 +245,13 @@
  186.         if ((val = memchr(s, '=', (p - s)))) { /* have a value */
  187.             unsigned int val_len, new_val_len;
  188.  
  189. +           if (++PG(input_vars_count) > PG(max_input_vars)) {
  190. +               s = p + 1;
  191. +               continue;
  192. +           } else if (PG(input_vars_count) == PG(max_input_vars)) {
  193. +               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variables reached %ld. To increase the limit change max_input_vars in php.ini.", PG(max_input_vars));
  194. +           }
  195. +
  196.             var = s;
  197.  
  198.             php_url_decode(var, (val - s));
  199. @@ -384,6 +374,12 @@
  200.             }
  201.         }
  202.  
  203. +       if (++PG(input_vars_count) > PG(max_input_vars)) {
  204. +           goto next_cookie;
  205. +       } else if (PG(input_vars_count) == PG(max_input_vars)) {
  206. +           php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variables reached %ld. To increase the limit change max_input_vars in php.ini.", PG(max_input_vars));
  207. +       }
  208. +
  209.         if (val) { /* have a value */
  210.             int val_len;
  211.             unsigned int new_val_len;
  212. Index: trunk/main/main.c
  213. ===================================================================
  214. --- trunk/main/main.c   (revision 323122)
  215. +++ trunk/main/main.c   (working copy)
  216. @@ -531,7 +531,7 @@
  217.     STD_PHP_INI_ENTRY("post_max_size",          "8M",       PHP_INI_SYSTEM|PHP_INI_PERDIR,      OnUpdateLong,           post_max_size,          sapi_globals_struct,sapi_globals)
  218.     STD_PHP_INI_ENTRY("upload_tmp_dir",         NULL,       PHP_INI_SYSTEM,     OnUpdateStringUnempty,  upload_tmp_dir,         php_core_globals,   core_globals)
  219.     STD_PHP_INI_ENTRY("max_input_nesting_level", "64",      PHP_INI_SYSTEM|PHP_INI_PERDIR,      OnUpdateLongGEZero, max_input_nesting_level,            php_core_globals,   core_globals)
  220. -   STD_PHP_INI_ENTRY("max_input_vars",         "1000",     PHP_INI_SYSTEM|PHP_INI_PERDIR,      OnUpdateLongGEZero, max_input_vars,             php_core_globals,   core_globals)
  221. +   STD_PHP_INI_ENTRY("max_input_vars",         "4096",     PHP_INI_SYSTEM|PHP_INI_PERDIR,      OnUpdateLongGEZero, max_input_vars,             php_core_globals,   core_globals)
  222.  
  223.     STD_PHP_INI_ENTRY("user_dir",               NULL,       PHP_INI_SYSTEM,     OnUpdateString,         user_dir,               php_core_globals,   core_globals)
  224.     STD_PHP_INI_ENTRY("variables_order",        "EGPCS",    PHP_INI_SYSTEM|PHP_INI_PERDIR,      OnUpdateStringUnempty,  variables_order,        php_core_globalscore_globals)
  225. @@ -1806,6 +1806,8 @@
  226.         zend_unset_timeout(TSRMLS_C);
  227.     } zend_end_try();
  228.  
  229. +   PG(input_vars_count) = 0;
  230. +
  231.  #ifdef PHP_WIN32
  232.     if (PG(com_initialized)) {
  233.         CoUninitialize();
Advertisement
Add Comment
Please, Sign In to add comment