Commit Graph

1589 Commits

Author SHA1 Message Date
Nikita Popov
6dd85f83f7 Fixed bug #80781
zend_find_array_dim_slow() may throw, make sure to handle this.
This backports the code we already use for this on PHP-8.0,
and also backports an exception check that makes this easier to
catch.
2021-02-22 09:36:43 +01:00
Nikita Popov
7b7d99839c Fix symtable cache being used while cleaning symtable
We need to first clean the symtable and then check whether a cache
slot is available for it. Otherwise, it may happen that a destructor
runs while cleaning the table and uses up all the remaining slots
in the cache.

This is particularly insidious because once we overflow the cache,
the first pointer we modify is symtable_cache_ptr, making it hard
to understand what happened after the fact.

Fixes oss-fuzz #30815.
2021-02-15 14:58:38 +01: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
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
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
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
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
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
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
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
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
Dmitry Stogov
5d0ef4c239 Make opcodes to return de-refereced values of typed references (in the same was as for non-typed) 2020-02-06 15:48:54 +03:00
Dmitry Stogov
db7193f31e Fixed bug #79094 (Crashing when running recursion function) 2020-01-31 10:34:04 +03:00
Nikita Popov
f77747b06c Properly propagate url_stat exceptions during include
Make sure we abort operations early, and that we don't emit
additional warnings or errors if an exception has been thrown.
2019-12-30 22:56:42 +01:00
Nikita Popov
527ad1d80c Avoid signed integer overflow in string offset check
Cast to size_t before performing operations instead of afterwards.
2019-12-19 11:47:50 +01:00
Nikita Popov
df08d6bffe Fix leak in assign_ref with function
As far as I can see, the retval copying is already done in all
callers of this function, so it should not be duplicated here.
2019-12-18 17:18:10 +01:00
Nikita Popov
0301ab70b3 Fix const/cv freeing on failed reference assignment 2019-12-18 09:54:10 +01:00
Dmitry Stogov
03d1c788ea Export zend_init_func_run_time_cache() 2019-12-09 15:58:00 +03:00
Nikita Popov
f841388781 Don't autoload when checking property types
Noticed while working on union types: We do not load argument and
return types during type checks, but we do load property types.

I'm normalizing the behavior towards the existing status quo (not
loading), though we may consider loading everywhere (all types,
and instanceof) in order to properly support class aliases.
2019-10-23 12:21:30 +02:00
Nikita Popov
5a076e670a Return error_zval form get_property_ptr_ptr on exception
This goes in the reverse direction of 4463acb951.
After looking around a bit, it seems that we already check for
Z_ISERROR_P() on the get_property_ptr_ptr return value in other places.
So do this in zend_fetch_property_address() as well, and also make
sure that EG(error_zval) is indeed returned on exception in
get_property_ptr_ptr.

In particular, this fixes the duplicate exceptions that we used to
get because first get_property_ptr_ptr threw one and then
read_property throws the same exception again.
2019-10-10 15:14:04 +02:00
Nikita Popov
4463acb951 Explicitly check for exceptions in by-ref obj prop assign
Relying on setting ERROR if an exception happened during the
property address fetch is both a bit fragile and may pessimize
other codepaths that will check for exceptions in the VM. Adding
an extra exception check instead, which should also allow us to
drop the use of ERROR in this area in master.
2019-10-10 14:41:35 +02:00
Nikita Popov
382f9b28e8 Fix leak on "Cannot assign by reference to overloaded object" error 2019-10-10 10:07:54 +02:00
Nikita Popov
21148679d1 Handle "non well formed" exception during ZPP
Previously if the "non well formed" notice was converted into an
exception we'd still end up executing the function.

Also drop the now unnecessary EG(exception) checks in the engine.

Additionally remote a bogus exception in zend_is_callable: It
should only be writing to error, but not directly throwing.
2019-10-08 17:17:49 +02:00
Nikita Popov
ad3ddf46f9 Fixed bug #78644
Make sure the initialize the result of FETCH_OBJ_UNSET operations.
I'm using a NULL value rather than ERROR here, because the latter
no longer exists in master.
2019-10-08 14:32:49 +02:00
Dmitry Stogov
51d9f32dbe Fixed bug #78531 (Crash when using undefined variable as object 2019-09-13 01:42:02 +03:00
Dmitry Stogov
697266a84e Eliminate checks using ZEND_CONST_COND() macro 2019-09-12 18:29:19 +03:00
Nikita Popov
b6f76aca54 Improve exception handling for abstract/deprecated calls
Reuse existing arg freeing loop instead of duplicating it.

Additionally also handle deprecated in DO_FCALL_BY_NAME.
2019-09-04 15:19:21 +02:00
Nikita Popov
4bb7282742 Fix handling of abstract/deprecated exception
The exception mechanism assumes that exceptions from DO_FCALL are
already happening after the function call. This means that we are
currently leaking the passed arguments, and I think we can also
corrupt the VM stack due to incorrect frame linking in some cases
(there are assertion failures if the VM stack page size is reduced).

Instead handle the stack frame freeing manually for this special
case.
2019-09-04 12:46:00 +02:00
Dmitry Stogov
d1fd4607d0 Inline zend_zval_ptr() in executor explicitely (only on hot paths) 2019-08-06 16:28:42 +03:00
Nikita Popov
99d4b2bddc Mark _get_zval_ptr_deref as unused 2019-07-24 20:51:19 +02:00
Nikita Popov
9e4603f772 Try to fix macos build
By avoiding unused variable opline warnings. Also clean up the
replacement of ZEND_VM_SPEC -- we were sometimes treating it as
an always-defined constant with a value (what it actually is) and
sometimes as a conditionally defined constant (which it isn't, but
which still worked thanks to the specializer). Switch to only
treating it as a constant with a value.
2019-07-24 09:44:55 +02:00
Nikita Popov
0ba7c3eadf Deprecate array_key_exists() on objects 2019-07-22 11:39:52 +02:00
Dmitry Stogov
ee5828205e Separate "cold" and common unspecialized code 2019-07-17 00:52:26 +03:00
Nikita Popov
a0f450a023 Remove unused _get_zval_ptr_cv_BP_VAR_UNSET function
To fix the macos -Werror build.
2019-07-16 15:53:55 +02:00
Dmitry Stogov
1d4c38421a Delay IS_UNDEF checks 2019-07-16 11:16:45 +03:00
Dmitry Stogov
ef1a1a0698 Separate "cold" parts of comparison instructions 2019-07-11 20:44:39 +03:00
Nikita Popov
c42b7dd6d3 Throw notice on array access on illegal type
No notice is thrown for list() accesses, because we did not come
to an agreement regarding patterns like

    while ([$key, $value] = yield $it->next()) { ... }

where silent null access may be desirable.

No effort is made to suppress multiple notices in access chains
likes $x[0][0][0], because the technical complexity this causes
does not seem worthwhile.

RFC: https://wiki.php.net/rfc/notice-for-non-valid-array-container
2019-07-10 12:02:14 +02:00
Nikita Popov
2bca35eacc Rename support_strings to !is_list
In preparation for more behavior that depends on whether it it is
a list() access. Using support_strings for that would be
confusing.
2019-07-10 11:10:17 +02:00
Dmitry Stogov
48ca5a1e17 Replace ZEND_ASSIGN_ADD (and others) by ZEND_ASSIGN_OP, ZEND_ASSIGN_DIM_OP, ZEND_ASSGIN_OBJ_OP and ZEND_ASSIGN_STATIC_PROP_OP 2019-07-05 12:03:25 +03:00
Dmitry Stogov
ef05eab432 Improve zend_binary_assign_op helpers.
Reorder opcode numbers to make ADD-POW and ASSIGN_ADD-ASSIGN_POW opcodes sequencional.
2019-07-04 17:25:43 +03:00
Dmitry Stogov
09041151de Better optimization in RELEASE build. ZEND_ASSERT(s) prevented optimization 2019-07-03 20:19:56 +03:00
Dmitry Stogov
56b8b165f8 Optimization of INC/DEC helpers 2019-07-03 10:33:03 +03:00
Dmitry Stogov
baa883d3fc Fixed build without global register variables 2019-07-02 11:03:22 +03:00
Dmitry Stogov
cbbd473bdd Separate slow code 2019-07-02 01:16:34 +03:00
Dmitry Stogov
f2b6b2eee8 Micro-optimization 2019-07-01 16:57:25 +03:00
Dmitry Stogov
e1e8e670df Cleanup 2019-06-21 11:43:17 +03:00
Nikita Popov
eaafb69eea Change indexing scheme for symtable_cache
symtable_cache_ptr now points to the first unused symtable_cache
entry, rahter than the last used one. This avoids taking a pointer
to the minus first element of the array, which is UB. Instead we
take a pointer to the end plus one, which is not UB.
2019-06-20 16:21:39 +02:00
Nikita Popov
268b5fec8e Fixed bug #78182 2019-06-19 16:35:12 +02:00