Commit Graph

474 Commits

Author SHA1 Message Date
Nikita Popov
b22daa3a06 Merge branch 'PHP-7.4'
* PHP-7.4:
  Throw Error when referencing uninit typed prop in __sleep
2020-01-06 18:47:44 +01:00
Nikita Popov
846b647953 Throw Error when referencing uninit typed prop in __sleep
Previously this generated a notice, but would likely generate an
Error when unserializing.

Now we treat it with the same distinction as direct property
accesses, i.e. referencing an unset/undefined normal property
stays a notice, while a typed property becomes an Error exception.

This fixed bug #79002.

Closes GH-5050.
2020-01-06 18:47:27 +01:00
Máté Kocsis
aadd3aaed9
Use RETURN_THROWS() in various places 2020-01-03 21:10:24 +01:00
Nikita Popov
0d35f8e3f2 Merge branch 'PHP-7.4'
* PHP-7.4:
  Populate hashtable of __sleep() properties
  Deref names returned by __sleep()
  Extract php_var_serialize_nested_data() function
2020-01-02 11:14:16 +01:00
Nikita Popov
90fea67546 Populate hashtable of __sleep() properties
Instead of populating a hashtable of property names and then
directly serializing.

This has the advantage of a) detecting duplicate properties more
precisely and b) gives us the ability to discard values without
rewriting the serialization string after the fact for GH-5027.
2020-01-02 11:14:01 +01:00
Nikita Popov
de0ca4734e Deref names returned by __sleep() 2020-01-02 11:14:00 +01:00
Nikita Popov
701e8c66d1 Extract php_var_serialize_nested_data() function
And split code-paths for arrays and objects based on it.
2020-01-02 11:14:00 +01:00
George Peter Banyard
4782e8e28a Return empty string instead of NULL in serialize().
Modifiy its return type accordingly and arginfo.
2019-12-12 00:01:28 +01:00
Máté Kocsis
3b0a1905dd
Promote warning to exception in unserialize() 2019-12-11 18:47:59 +01:00
Christoph M. Becker
0e20220cfc Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #77638: var_export'ing certain class instances segfaults
2019-11-25 15:58:45 +01:00
Christoph M. Becker
717730ddd1 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #77638: var_export'ing certain class instances segfaults
2019-11-25 15:57:56 +01:00
Christoph M. Becker
23c65a8173 Fix #77638: var_export'ing certain class instances segfaults
If objects return immutable property hash tables (typically,
`zend_empty_array`), we must not try to apply recursion protection on
those.
2019-11-25 15:54:11 +01:00
Nikita Popov
647b1c7fcf Remove most uses of ZEND_PARSE_PARAMETERS_END_EX()
As ZPP now throws, it makes no sense to specify an explicit return
value.
2019-10-07 10:02:18 +02:00
Nikita Popov
1cde9e8528 Merge branch 'PHP-7.4' 2019-09-30 10:30:20 +02:00
Nikita Popov
1806ce9cb0 Add max_depth option to unserialize()
Add a max_depth option to unserialize and an unserialize_max_depth
ini setting, which can be used to control the depth limit. The
default value is 4096.

This option is intended to prevent stack overflows during the
unserialization of deeply nested structures.

This fixes bug #78549 and addresses oss-fuzz #17581, #17589, #17664,
and #17788.
2019-09-30 10:28:24 +02:00
Gabriel Caruso
5d6e923d46
Remove mention of PHP major version in Copyright headers
Closes GH-4732.
2019-09-25 14:51:43 +02:00
Nikita Popov
6276dd826b Use ZEND_TYPE_IS_SET() when checking for property types
Instead of a simple if or 0 comparison. This would no longer work
if zend_type is a struct.
2019-09-23 16:53:54 +02:00
Nikita Popov
9e8ba7891e Change representation of zend_type from type code to MAY_BE_* mask
This switches zend_type from storing a single IS_* type code to
storing a MAY_BE_* type mask. Right now most code still assumes
that there is only a single type in the mask (or two together
with MAY_BE_NULL). But this will make it a lot simpler to introduce
union types.

An additional advantage (and why I'm doing this separately), is
that a number of special cases no longer need to be handled
separately: We can do a single mask & (1 << type) check to handle
all simple types, booleans (true|false) and null.
2019-09-23 15:31:35 +02:00
Nikita Popov
a31f46421d Allow exceptions in __toString()
RFC: https://wiki.php.net/rfc/tostring_exceptions

And convert some object to string conversion related recoverable
fatal errors into Error exceptions.

Improve exception safety of internal code performing string
conversions.
2019-06-05 14:25:07 +02:00
Dmitry Stogov
83804519df Replace ZVAL_COPY() and ZVAL_COPY_VALUE() for IS_OBJECT by cheaper macros 2019-05-28 20:10:02 +03:00
Nikita Popov
cb145e18b2 Fixed bug #77873 2019-04-09 17:27:02 +02:00
Nikita Popov
d373c11e71 Implement new custom object serialization mechanism
RFC: https://wiki.php.net/rfc/custom_object_serialization
2019-03-22 10:43:06 +01:00
Nikita Popov
cc354a0790 Merge branch 'PHP-7.3' into PHP-7.4 2019-03-11 15:36:40 +01:00
Nikita Popov
6818ca3c02 Merge branch 'PHP-7.2' into PHP-7.3 2019-03-11 15:36:27 +01:00
Nikita Popov
1fd32e9c2f Fixed bug #76717
Print INT_MIN as -INT_MAX-1 to avoid it getting parsed as a float
literal due to integer overflow.
2019-03-11 15:35:02 +01:00
c9s
9f6f6fe219 Remove function_table var from the caller
function_table var is not used in call_user_function macro anymore
hence replace the usage with NULL
2019-03-11 10:00:39 +01:00
Nikita Popov
2210c6823c Merge branch 'PHP-7.3' into PHP-7.4 2019-02-21 12:06:48 +01:00
Nikita Popov
af324e24df Fix issue mentioned in #77302
Apparently Serializable::serialize() can return NULL, which is encoded
as N;. As we do not allow back-references to non-object values in
PHP 7.3 we need to make sure that any references are also compiled to
N;.
2019-02-21 12:04:49 +01:00
Peter Kokot
92ac598aab Remove local variables
This patch removes the so called local variables defined per
file basis for certain editors to properly show tab width, and
similar settings. These are mainly used by Vim and Emacs editors
yet with recent changes the once working definitions don't work
anymore in Vim without custom plugins or additional configuration.
Neither are these settings synced across the PHP code base.

A simpler and better approach is EditorConfig and fixing code
using some code style fixing tools in the future instead.

This patch also removes the so called modelines for Vim. Modelines
allow Vim editor specifically to set some editor configuration such as
syntax highlighting, indentation style and tab width to be set in the
first line or the last 5 lines per file basis. Since the php test
files have syntax highlighting already set in most editors properly and
EditorConfig takes care of the indentation settings, this patch removes
these as well for the Vim 6.0 and newer versions.

With the removal of local variables for certain editors such as
Emacs and Vim, the footer is also probably not needed anymore when
creating extensions using ext_skel.php script.

Additionally, Vim modelines for setting php syntax and some editor
settings has been removed from some *.phpt files.  All these are
mostly not relevant for phpt files neither work properly in the
middle of the file.
2019-02-03 21:03:00 +01:00
Zeev Suraski
0cf7de1c70 Remove yearly range from copyright notice 2019-01-30 11:03:12 +02:00
Nikita Popov
e219ec144e Implement typed properties
RFC: https://wiki.php.net/rfc/typed_properties_v2

This is a squash of PR #3734, which is a squash of PR #3313.

Co-authored-by: Bob Weinand <bobwei9@hotmail.com>
Co-authored-by: Joe Watkins <krakjoe@php.net>
Co-authored-by: Dmitry Stogov <dmitry@zend.com>
2019-01-11 15:49:06 +01:00
Dmitry Stogov
71f430cf06 Improve unserialize() 2018-12-12 20:04:36 +03:00
Nikita Popov
7ec8087f80 Introduce get_properties_for() handler
This handler allows getting the object properties for a particular
purpose, such as array casting, serialization, etc.
2018-10-10 10:39:10 +02:00
Nikita Popov
d982bbe175 Fix ref ID handling when serializing $GLOBALS
This was already broken previously, but in PHP 7.3 stricter
validation during unserialization made this into an error.
2018-10-08 13:16:23 +02:00
Peter Kokot
8d3f8ca12a Remove unused Git attributes ident
The $Id$ keywords were used in Subversion where they can be substituted
with filename, last revision number change, last changed date, and last
user who changed it.

In Git this functionality is different and can be done with Git attribute
ident. These need to be defined manually for each file in the
.gitattributes file and are afterwards replaced with 40-character
hexadecimal blob object name which is based only on the particular file
contents.

This patch simplifies handling of $Id$ keywords by removing them since
they are not used anymore.
2018-07-25 00:53:25 +02:00
Andrea Faulds
e4e9cd8355 Export stdClass objects using (object) cast (fixes #48016)
Before this change, var_export()'s output for stdClass objects calls
the non-existent stdClass::__set_state method, and is therefore useless.

This commit makes var_export() output an (object) cast from an array
instead, which when evaluated, will produce a stdClass object. Other
classes see unchanged output.
2018-07-12 13:22:26 +02:00
Dmitry Stogov
4a475a4976 Replace legacy zval_dtor() by zval_ptr_dtor_nogc() or even more specialized destructors.
zval_dtor() doesn't make a lot of sense in PHP-7.* and it's used incorrectly in some places.
Its occurances should be replaced by zval_ptr_dtor() or zval_ptr_dtor_nogc(), or even more specialized destructors.
2018-07-04 19:22:24 +03:00
Dmitry Stogov
dd932f7e63 Changed php_add[c]slashes prototypes (removed should_free argument) 2018-06-29 00:19:16 +03:00
Dmitry Stogov
d90c6f2443 Removed useless zval_ptr_dtor() 2018-05-29 17:58:06 +03:00
Dmitry Stogov
5eb1f92f31 Use zend_string_release_ex() instread of zend_string_release() in places, where we sure about string persistence. 2018-05-28 16:27:12 +03:00
Xinchen Hui
a6519d0514 year++ 2018-01-02 12:57:58 +08:00
Xinchen Hui
7a7ec01a49 year++ 2018-01-02 12:55:14 +08:00
Dmitry Stogov
cc12acefcd Use cheaper functions 2017-12-04 13:21:35 +03:00
Anatol Belski
80d6eb6806 Fix unsigned comparisons and remove dead code
Fix unsigned comparison

Cleanup never executed block

Fix unsigned comparison

Fix unsigned comparison, diff can't be < 0

Fix unsigned comparison

Fix unsigned comparison

Remove dead code
2017-11-17 22:38:44 +01:00
Dmitry Stogov
288c1dd6da Missed change 2017-11-16 18:10:15 +03:00
Dmitry Stogov
ccc12b82da Avoid unnecessary reference-counting on strings. 2017-11-16 17:09:32 +03:00
Dmitry Stogov
cf67a421e9 Use per-request heap instead of system one 2017-10-27 14:45:54 +03:00
Dmitry Stogov
61ef91bf0d Revert "Allow internal functions to return values by reference (this was disabled in implementation of DO_ICALL, but enabled in DO_FCALL)."
This reverts commit da781a5ac2.
2017-10-17 13:25:19 +03:00
Dmitry Stogov
da781a5ac2 Allow internal functions to return values by reference (this was disabled in implementation of DO_ICALL, but enabled in DO_FCALL).
However, don't require internal functions returning by reference to return a reference.
Mark unserialize() as returning by reference and remove unwrap_reference hack, to allow proper returning of self referenced arrays using a reference.
Currently unserialize() is the only internal function that may return a reference.
2017-10-17 11:50:34 +03:00
Dmitry Stogov
cb9d81ef4f Refactored recursion pretection 2017-10-06 01:34:50 +03:00