scottmac Thu May 14 22:02:08 2009 UTC
Modified files: (Branch: PHP_5_3)
/php-src/ext/json JSON_parser.c JSON_parser.h json.c
Log:
MFH Allow a custom recursion depth to be specified for json_decode()
http://cvs.php.net/viewvc.cgi/php-src/ext/json/JSON_parser.c?r1=1.1.2.12.2.9&r2=1.1.2.12.2.10&diff_format=u
Index: php-src/ext/json/JSON_parser.c
diff -u php-src/ext/json/JSON_parser.c:1.1.2.12.2.9
php-src/ext/json/JSON_parser.c:1.1.2.12.2.10
--- php-src/ext/json/JSON_parser.c:1.1.2.12.2.9 Thu Mar 19 19:26:00 2009
+++ php-src/ext/json/JSON_parser.c Thu May 14 22:02:08 2009
@@ -247,6 +247,11 @@
jp->top = -1;
jp->error_code = PHP_JSON_ERROR_NONE;
jp->stack = (int*)ecalloc(depth, sizeof(int));
+ if (depth > JSON_PARSER_DEFAULT_DEPTH) {
+ jp->the_zstack = (zval **)safe_emalloc(depth, sizeof(zval), 0);
+ } else {
+ jp->the_zstack = &jp->the_static_zstack[0];
+ }
push(jp, MODE_DONE);
return jp;
}
@@ -258,6 +263,9 @@
free_JSON_parser(JSON_parser jp)
{
efree((void*)jp->stack);
+ if (jp->the_zstack != &jp->the_static_zstack[0]) {
+ efree(jp->the_zstack);
+ }
efree((void*)jp);
return false;
}
http://cvs.php.net/viewvc.cgi/php-src/ext/json/JSON_parser.h?r1=1.1.2.1.2.2&r2=1.1.2.1.2.3&diff_format=u
Index: php-src/ext/json/JSON_parser.h
diff -u php-src/ext/json/JSON_parser.h:1.1.2.1.2.2
php-src/ext/json/JSON_parser.h:1.1.2.1.2.3
--- php-src/ext/json/JSON_parser.h:1.1.2.1.2.2 Fri Dec 19 02:00:57 2008
+++ php-src/ext/json/JSON_parser.h Thu May 14 22:02:08 2009
@@ -6,7 +6,7 @@
#include "php.h"
#include "ext/standard/php_smart_str.h"
-#define JSON_PARSER_MAX_DEPTH 512
+#define JSON_PARSER_DEFAULT_DEPTH 512
typedef struct JSON_parser_struct {
int state;
@@ -14,8 +14,8 @@
int top;
int error_code;
int* stack;
- zval *the_zstack[JSON_PARSER_MAX_DEPTH];
-
+ zval **the_zstack;
+ zval *the_static_zstack[JSON_PARSER_DEFAULT_DEPTH];
} * JSON_parser;
enum error_codes {
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.9.2.19.2.19&r2=1.9.2.19.2.20&diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.9.2.19.2.19
php-src/ext/json/json.c:1.9.2.19.2.20
--- php-src/ext/json/json.c:1.9.2.19.2.19 Tue Mar 17 23:26:02 2009
+++ php-src/ext/json/json.c Thu May 14 22:02:08 2009
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: json.c,v 1.9.2.19.2.19 2009/03/17 23:26:02 scottmac Exp $ */
+/* $Id: json.c,v 1.9.2.19.2.20 2009/05/14 22:02:08 scottmac Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -494,7 +494,7 @@
char *str;
int str_len, utf16_len;
zend_bool assoc = 0; /* return JS objects as PHP objects by default */
- long depth = JSON_PARSER_MAX_DEPTH;
+ long depth = JSON_PARSER_DEFAULT_DEPTH;
zval *z;
unsigned short *utf16;
JSON_parser jp;
@@ -517,9 +517,9 @@
RETURN_NULL();
}
- /* can be removed once we remove the max depth limit */
- if (depth <= 0 || depth > JSON_PARSER_MAX_DEPTH) {
- depth = JSON_PARSER_MAX_DEPTH;
+ if (depth <= 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Depth must greater
than zero.");
+ RETURN_NULL();
}
ALLOC_INIT_ZVAL(z);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php