php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #72073
Patch jsonserializedepth revision 2016-04-22 17:11 UTC by jani dot ollikainen at valve dot fi
revision 2016-04-22 16:50 UTC by jani dot ollikainen at valve dot fi
revision 2016-04-22 16:48 UTC by jani dot ollikainen at valve dot fi
revision 2016-04-22 08:24 UTC by jani dot ollikainen at valve dot fi
Patch jsonserializedepth-55 revision 2016-04-22 15:09 UTC by jani dot ollikainen at valve dot fi

Patch jsonserializedepth for JSON related Bug #72073

Patch version 2016-04-22 17:11 UTC

Return to Bug #72073 | Download this patch
This patch renders other patches obsolete

Obsolete patches:

Patch Revisions: 2016-04-22 17:11 UTC | 2016-04-22 16:50 UTC | 2016-04-22 16:48 UTC | 2016-04-22 08:24 UTC

Developer: jani.ollikainen@valve.fi


 diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c
 index c3aa348..e64a09a 100644
 --- a/ext/json/json_encoder.c
 +++ b/ext/json/json_encoder.c
 @@ -446,7 +446,7 @@ static void php_json_escape_string(smart_str *buf, char *s, size_t len, int opti
  static void php_json_encode_serializable_object(smart_str *buf, zval *val, int options) /* {{{ */
 --- php-json-1.3.2.orig/jsonc-1.3.2/json.c
 +++ php-json-1.3.2/jsonc-1.3.2/json.c
 @@ -681,7 +681,7 @@ static void json_escape_string(smart_str
  static void json_encode_serializable_object(smart_str *buf, zval *val, int options TSRMLS_DC) /* {{{ */
   {
   	zend_class_entry *ce = Z_OBJCE_P(val);
 -	zval retval, fname;
 +	zval retval, fname, args[1];
 -	zval *retval = NULL, fname;
 +	zval *retval = NULL, fname, **args[1], *depth;
   	HashTable* myht;
   
   	if (Z_TYPE_P(val) == IS_ARRAY) {
 @@ -461,9 +461,10 @@ static void php_json_encode_serializable_object(smart_str *buf, zval *val, int o
 @@ -696,16 +696,21 @@ static void json_encode_serializable_obj
   		return;
   	}
   
 +	ZVAL_LONG(&args[0], JSON_G(encoder_depth));
  	ZVAL_STRING(&fname, "jsonSerialize");
 +	MAKE_STD_ZVAL(depth);
 +	ZVAL_LONG(depth, JSON_G(encoder_depth));
 +	args[0] = &depth;
  	ZVAL_STRING(&fname, "jsonSerialize", 0);
   
 -	if (FAILURE == call_user_function_ex(EG(function_table), val, &fname, &retval, 0, NULL, 1, NULL) || Z_TYPE(retval) == IS_UNDEF) {
 +	if (FAILURE == call_user_function_ex(EG(function_table), val, &fname, &retval, 1, args, 1, NULL) || Z_TYPE(retval) == IS_UNDEF) {
  		zend_throw_exception_ex(NULL, 0, "Failed calling %s::jsonSerialize()", ZSTR_VAL(ce->name));
 -	if (FAILURE == call_user_function_ex(EG(function_table), &val, &fname, &retval, 0, NULL, 1, NULL TSRMLS_CC) || !retval) {
 +	if (FAILURE == call_user_function_ex(EG(function_table), &val, &fname, &retval, 1, args, 1, NULL TSRMLS_CC) || !retval) {
  		zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Failed calling %s::jsonSerialize()", ce->name);
   		smart_str_appendl(buf, "null", sizeof("null") - 1);
  		zval_ptr_dtor(&fname);
 +		zval_ptr_dtor(&depth);
  		return;
  	}
  
  	if (EG(exception)) {
  		/* Error already raised */
 +		zval_ptr_dtor(&depth);
  		zval_ptr_dtor(&retval);
  		smart_str_appendl(buf, "null", sizeof("null") - 1);
  		return;
 @@ -720,6 +725,7 @@ static void json_encode_serializable_obj
  		php_json_encode(buf, retval, options TSRMLS_CC);
  	}
  
 +	zval_ptr_dtor(&depth);
  	zval_ptr_dtor(&retval);
  }
  /* }}} */
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 13:01:30 2024 UTC