Commit Graph

1748 Commits

Author SHA1 Message Date
Nikita Popov
f5dbebd82e Accept zend_string instead of zval in zend_compile_string 2020-09-07 11:42:21 +02:00
Nikita Popov
8b6b2bda09 Fix by-ref list assign LIST_W+MAKE_REF separation
Shift the responsibility for emitting MAKE_REF to the list assignment
code, to make sure that LIST_W and MAKE_REF are directly adjacent,
and there are no opcodes in between that could modify the LIST_W
result.

Additionally, adjust the zend_wrong_string_offset() code to not
perform a loop over opcodes and assert that the next opcode is
a relevant one. The VM write-safety model requires this.

This is a followup to a07c1f56aa
and the full fix for oss-fuzz #25352.
2020-09-02 10:26:55 +02:00
Nikita Popov
aedc7b0fb4 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix infinite loop on string offset during by-ref list assign
2020-09-02 10:16:46 +02:00
Nikita Popov
605ee9c8eb Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix infinite loop on string offset during by-ref list assign
2020-09-02 10:16:35 +02:00
Nikita Popov
a07c1f56aa Fix infinite loop on string offset during by-ref list assign
There is a deeper underlying issue here, in that the opcodes violate
VM write-fetch safety, but let's fix the infinite loop first.

This fixes oss-fuzz #25352.
2020-09-02 10:16:05 +02:00
Levi Morrison
66c3e900e2 Add zend_observer API
Closes GH-5857.

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
Co-authored-by: Sammy Powers <sammyk@datadoghq.com>
2020-09-01 09:59:59 -06:00
Nikita Popov
061c708a93 Correctly report failure in zend_handle_undef_args()
And do the check before increfing the closure object, otherwise
we'd have to release it as well.

Fixes oss-fuzz #25313.
2020-08-31 10:37:55 +02:00
Nikita Popov
b2bc2c62fa Remove unnecessary cache_slot arguments
zend_verify_type_error_common() no longer needs the cache_slot,
so drop it there and from all users.
2020-08-28 17:15:09 +02:00
George Peter Banyard
fa8d9b1183 Improve type declarations for Zend APIs
Voidification of Zend API which always succeeded
Use bool argument types instead of int for boolean arguments
Use bool return type for functions which return true/false (1/0)
Use zend_result return type for functions which return SUCCESS/FAILURE as they don't follow normal boolean semantics

Closes GH-6002
2020-08-28 15:41:27 +02:00
Nikita Popov
a2bbd8f01f Fix leak in typed reference assignment
We're only creating tmp here to compare against the existing
coerced_value. We need to destroy it in all cases.
2020-08-27 14:40:35 +02:00
Nikita Popov
e069032e5c Merge branch 'PHP-7.4'
* PHP-7.4:
  Property handle read_property exception in fetch_property_address
2020-08-26 16:13:10 +02:00
Nikita Popov
247105ae1a Property handle read_property exception in fetch_property_address
Otherwise we leak (and corrupt uninitialized_zval).
2020-08-26 16:12:34 +02:00
Nikita Popov
74c4381806 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79947
2020-08-10 10:13:34 +02:00
Nikita Popov
2d087210eb Fixed bug #79947
Move the FREE_OP for op_data out of the zend_binary_assign_op_dim_slow()
slow path, so it can be used by the other error path as well. This
makes ASSIGN_DIM_OP structurally more similar to ASSIGN_DIM.
2020-08-10 10:11:56 +02:00
Nikita Popov
c48b745f00 Promote "undefined array key" notice to warning
This implements the last remaining part of the
https://wiki.php.net/rfc/engine_warnings RFC.

Closes GH-5927.
2020-08-03 14:40:50 +02:00
Nikita Popov
d92229d8c7 Implement named parameters
From an engine perspective, named parameters mainly add three
concepts:

 * The SEND_* opcodes now accept a CONST op2, which is the
   argument name. For now, it is looked up by linear scan and
   runtime cached.
 * This may leave UNDEF arguments on the stack. To avoid having
   to deal with them in other places, a CHECK_UNDEF_ARGS opcode
   is used to either replace them with defaults, or error.
 * For variadic functions, EX(extra_named_params) are collected
   and need to be freed based on ZEND_CALL_HAS_EXTRA_NAMED_PARAMS.

RFC: https://wiki.php.net/rfc/named_params

Closes GH-5357.
2020-07-31 15:53:36 +02:00
Nikita Popov
a6e63b42c3 Make check in RECV_VARIADIC more precise
Fetch arg_info only once (it's always the same one...) and check
ZEND_TYPE_IS_SET on it, rather than checking if *any* parameter
has a type.
2020-07-31 12:02:28 +02:00
George Peter Banyard
b2248789ed Implement 'Saner Numeric Strings' RFC:
RFC: https://wiki.php.net/rfc/saner-numeric-strings

This removes the -1 allow_error mode from is_numeric_string functions and replaces it by
a trailing boolean out argument to preserve BC in a couple of places.

Most of the changes can be resumed to "numeric" strings which emitted a E_NOTICE now emit
a E_WARNING and "numeric" strings which emitted a E_WARNING now throw a TypeError.

This mostly affects:
 - String offsets
 - Arithmetic operations
 - Bitwise operations

Closes GH-5762
2020-07-29 02:51:09 +01:00
Nikita Popov
e079e753dc Give zend_pass_function an arginfo
Now that the ZEND_ACC_VARIADIC flag is set, we should also make
sure there is a variadic arg that can be looked up.
2020-07-21 16:01:45 +02:00
Nikita Popov
38fb1f8383 Check for missing arginfo arguments
Internal functions error when too many arguments are passed. Make
this part of the verification we do in debug builds. This will
help avoid cases where an argument is missing in the stubs,
as recently encountered in 6d96f0f.
2020-07-21 14:17:29 +02:00
Nikita Popov
f60cf0cfe7 Remove type argument from zend_get_zval_ptr
As pointed out by Levi, this is unused, and we already changed
the signature of this function for PHP 8.
2020-07-15 09:51:51 +02:00
Máté Kocsis
d30cd7d7e7
Review the usage of apostrophes in error messages
Closes GH-5590
2020-07-10 21:05:28 +02:00
George Peter Banyard
2297a6d364 Use dedicated function for illegal offset type error 2020-07-10 16:49:52 +02:00
Nikita Popov
613a56d1cb Remove FREE_UNFETCHED concept
In master normal FREE_OPs work like FREE_UNFETCHED_OP used to, so
there is no point in keeping this distinction anymore, it's just
confusing.
2020-07-09 11:58:33 +02:00
Nikita Popov
e45f7053cf Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79793
2020-07-07 16:33:06 +02:00
Nikita Popov
77acc8a069 Fixed bug #79793
Make sure the string key is not released while throwing the
undefined index warning.
2020-07-07 16:29:48 +02:00
Nikita Popov
beb002a867 Fixed bug #79791
First throw the undefined variable warning, and then set the
variable to null. Otherwise we're not guaranteed that it's
actually null afterwards.
2020-07-07 16:00:50 +02:00
Nikita Popov
cdc4ea2a5c JIT support for undefined index/offset handling 2020-07-07 15:13:03 +02:00
Nikita Popov
f497b69944 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79784
2020-07-07 14:24:39 +02:00
Nikita Popov
62bec0e083 Fixed bug #79784
The fix here is essentially the same as for bug #78598, just for
the undefined variable notice, rather than the undefined index one.
2020-07-07 14:22:58 +02:00
Nikita Popov
2c73bf7e3f Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78598
2020-07-07 12:28:35 +02:00
Nikita Popov
220880ad2d Fixed bug #78598
When performing an RW modification of an array offset, the undefined
offset warning may call an error handler / OB callback, which may
destroy the array we're supposed to change. Detect this by temporarily
incrementing the reference count. If we find that the array has been
modified/destroyed in the meantime, we do nothing -- the execution
model here would be that the modification has happened on the destroyed
version of the array.
2020-07-07 12:13:58 +02:00
Nikita Popov
b48bd671b8 Assert no exception if using NEXT_OPCODE()
When NEXT_OPCODE() is used instead of NEXT_OPCODE_CHECK_EXCEPTION(),
assert that there is indeed no exception.
2020-07-07 11:34:43 +02:00
Nikita Popov
e0743d0f91 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79779
2020-07-07 10:27:53 +02:00
Nikita Popov
6a9d934b2c Fixed bug #79779
ASSIGN_OBJ_REF was not handling in zend_wrong_string_offset.
2020-07-07 10:27:22 +02:00
Nikita Popov
795d2cbd71 Reuse warning function 2020-07-06 10:38:02 +02:00
Dmitry Stogov
a60cdcf084 A helper to trace executed source lines 2020-06-10 00:13:39 +03:00
twosee
83a77015ad Add helper APIs for maybe-interned string creation
Add ZVAL_CHAR/RETVAL_CHAR/RETURN_CHAR as a shortcut for using
ZVAL_INTERNED_STRING and ZSTR_CHAR.

Add zend_string_init_fast() as a helper for the empty string /
one char interned string / zend_string_init() pattern.

Also add corresponding ZVAL_STRINGL_FAST etc macros.

Closes GH-5684.
2020-06-08 15:31:52 +02:00
Dmitry Stogov
91f283a0bf micro-optimization 2020-06-05 14:20:39 +03:00
Benjamin Eberlei
a7908c2d11 Add Attributes
Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
2020-06-04 18:19:49 +02:00
Máté Kocsis
fbe30592d6
Improve type error messages when an object is given
From now on, we always display the given object's type instead of just reporting "object".
Additionally, make the format of return type errors match the format of argument errors.

Closes GH-5625
2020-05-26 19:06:19 +02:00
Nikita Popov
2daa89b1e6 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix zend_assign_to_typed_ref() implementation
2020-05-26 14:44:09 +02:00
Nikita Popov
314ab47e55 Fix zend_assign_to_typed_ref() implementation
There was some confusion going on here regarding the original
value vs the copied value.

I've dropped the needs_copy variable, because this code is not
inlined, so it would always be true anyway.

What we need to do is perform a move-assignment of the copied
value (in which case we don't care about performing the assignment
before destroying garbage), and destroying the original value
for the VAR/TMP cases. This is a bit complicated by the fact that
references are passed in via a separate ref variable, so we can't
just ptr_dtor the original variable.
2020-05-26 14:42:27 +02:00
Máté Kocsis
1179686f62
Improve error messages for invalid property access
Closes GH-5446
Co-authored-by:  Nikita Popov <nikita.ppv@gmail.com>
2020-05-18 08:27:00 +02:00
Máté Kocsis
93640db4d5
Improve error message for deprecated methods 2020-05-14 17:23:31 +02:00
Nikita Popov
c6a6ca078b Use zend_zval_type_name() API where possible
Rather than zend_get_type_by_const(Z_TYPE_P()).
2020-05-13 14:56:05 +02:00
Xinchen Hui
dd9d0a96d1 Fixed false alarm about tmp_name maybe unitialized 2020-05-07 14:16:02 +08:00
Nikita Popov
b3c7ab66fb Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #79434
2020-04-02 16:34:21 +02:00
Nikita Popov
cf68bc413b Fixed bug #79434 2020-04-02 16:34:03 +02:00
Máté Kocsis
36935e42ea
Improve undefined variable error messages
Closes GH-5312
2020-03-31 13:02:32 +02:00