diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-23 12:43:07 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-23 12:43:07 +0200 |
commit | 4831e150c5ada631c1480098b8a42cbf024d8899 (patch) | |
tree | 42f34492fb371f336fc123a5b7b176bd463a1eef /ext/json/json_encoder.c | |
parent | ce73841cdcfd86a2cf5d7e1c251095254985324d (diff) | |
download | php-git-4831e150c5ada631c1480098b8a42cbf024d8899.tar.gz |
Fixed bug #77843
Diffstat (limited to 'ext/json/json_encoder.c')
-rw-r--r-- | ext/json/json_encoder.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c index 8e3eecc0d8..4163291715 100644 --- a/ext/json/json_encoder.c +++ b/ext/json/json_encoder.c @@ -542,8 +542,16 @@ again: return php_json_encode_serializable_object(buf, val, options, encoder); } /* fallthrough -- Non-serializable object */ - case IS_ARRAY: - return php_json_encode_array(buf, val, options, encoder); + case IS_ARRAY: { + /* Avoid modifications (and potential freeing) of the array through a reference when a + * jsonSerialize() method is invoked. */ + zval zv; + int res; + ZVAL_COPY(&zv, val); + res = php_json_encode_array(buf, &zv, options, encoder); + zval_ptr_dtor_nogc(&zv); + return res; + } case IS_REFERENCE: val = Z_REFVAL_P(val); |