Commit Graph

3952 Commits

Author SHA1 Message Date
Dmitry Stogov
cbc0b1afeb Fix array clobering by user error handler
Fixes oss-fuzz #42234
2021-12-13 14:59:30 +03:00
Dmitry Stogov
8d7d87cdc4 Add test 2021-12-03 13:40:17 +03:00
Dmitry Stogov
94286cd596 Fix yet another indirect string modification by error handler problem 2021-12-02 16:16:54 +03:00
Dmitry Stogov
09547c64c2 Fix clobering of operand by error handler in assignment to string offset
In some cases new code requires two reallocations insead of one.

Fixes oss-fuzz #31716, #36196, #39739 and #40002
2021-12-02 00:24:05 +03:00
Dmitry Stogov
df434f056f Fix crash after indirect modification of string by user error handler
Fixes oss-fuzz #39346
2021-11-30 16:07:38 +03:00
Nikita Popov
be271f277e Fix bug #81652
We need to check not only for defs but also for uses of the
variable.
2021-11-24 15:18:31 +01:00
Tyson Andre
241bd3f454 Fix use after free when WeakMap is modified during field write
(When a value's destructor triggers a resizing or rehashing of the WeakMap)

Closes GH-7671
2021-11-20 16:52:25 -05:00
Nikita Popov
4d4fe7639f Fixed bug #81631
We need to save the opline before fetching the operand, as it may
throw an undef var warning.
2021-11-17 16:06:25 +01:00
Nikita Popov
9e25c4b3a6 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fixed bug #81626
2021-11-16 12:46:20 +01:00
Nikita Popov
d26965b247 Fixed bug #81626
Backport of a8926474cb to 7.4.
2021-11-16 12:45:33 +01:00
Nikita Popov
8c4a7f20f5 Fix COPY_TMP live range construction with optimization
The use may be optimized away, leaving us only with the free use.
Also fix off-by-one error in the other optimization case.
2021-11-11 10:35:34 +01:00
Nikita Popov
53df29bc29 Drop pi nodes for both old/new pred in replace_predecessor
We also need to drop pi nodes for new_pred here, as the pi node
restriction for new_pred is not necessarily true for control
coming from old_pred as well.

Fixes oss-fuzz #40782.
2021-11-08 14:56:42 +01:00
Nikita Popov
b302bfabe7 Implement Stringable automatically for internal classes
Requiring all internal classes (including those from 3rd-party
extensions) to implement Stringable if they provide __toString()
is too error prone. Case in point, our _ZendTestClass test class
was not doing so, resulting in preloading test failures after
recent changes.

Instead we automatically implement Stringable, the same as we do
for userland classes. We still allow explicit implementations,
but ignore them (normally they would result in an error due to
duplicate interface implementation). Finally, we need to be
careful about not trying to implement Stringable on Stringable
itself.

In some cases this changes the interface order, in particular the
automatic Stringable implementation will now come first.
2021-11-05 10:22:04 +01:00
Nikita Popov
d478ae73b1 Don't implement Stringable on traits
Traits do not support interfaces, so we should not implement
Stringable on them.

Also check the __toString() return type in the same way other
magic methods do, otherwise we would now miss the check in the
trait case.
2021-11-05 09:42:58 +01:00
Nikita Popov
7e67366a9b Remove unnecessary assertion
zend_class_implements_interface works fine if the "class" is an
interface, so simply drop this assertion. This avoids the need to
special case this situation.
2021-11-04 17:00:17 +01:00
Nikita Popov
4c171ed5eb Fix bug #81591: ignore_repeated_errors broken
We should suppress the error if the message is the same, not if
it's different. Apparently we had no test coverage for these
options.
2021-11-04 16:23:55 +01:00
Nikita Popov
d3932682e7 Fixed bug #81582
If __toString() comes from a trait, implement Stringable during
inheritance.
2021-11-04 11:58:33 +01:00
Nikita Popov
546e55864d Fix WeakReference uniquing is TAG_HT is used 2021-11-03 10:06:22 +01:00
Nikita Popov
2e29817005 Handle FETCH_DIM_R after FETCH_DIM_FUNC_ARG in inference
This can happen if a call is optimized, but FETCH_DIM_FUNC_ARG
cannot be converted to FETCH_DIM_R because it uses an UNUSED op2,
which is not supported by FETCH_DIM_R.

Fixes oss-fuzz 6144185837682688.
2021-11-01 14:26:36 +01:00
Nikita Popov
1a2fb90bf4 Fix finally exception chaining on recursion
In this case zend_exception_set_previous() would destroy the
fast_call exception and further accesses on ex would be invalid.
We should only update ex if we update EG(exception).

Fixes oss-fuzz #40464.
2021-11-01 11:44:32 +01:00
Nikita Popov
6974372fbb Fix bug #81510
Make the used arrays larger, because the previous sizes were not
slow enough on some hardware.
2021-10-18 12:45:26 +02:00
Nikita Popov
9ebe8494b8 Don't replace tmp with cv in YIELD argument
For by-ref generators, these may have different behavior.

Fixes oss-fuzz 6059739298004992.
2021-10-12 14:26:53 +02:00
Nikita Popov
a2e3ca1f5b Don't free FETCH_W operand if GLOBAL_LOCK
The error path performed the free unconditionally, while we should
not do it for GLOBAL_LOCK.

Fixes oss-fuzz #39868.
2021-10-12 12:44:35 +02:00
Dmitry Stogov
69fb20f106 Fixed assign coalesce. "$a[0] ??= $a" should evaluate the right $a first. 2021-10-05 20:23:56 +03:00
Nikita Popov
11a9b036a8 Fix duplicate undef warning in assign_dim_op
In case of auto-vivification we were fetching dim twice and as
such also emitting the undef var warning twice.
2021-10-05 15:51:11 +02:00
Nikita Popov
bbd3f714d7 Fix COPY_TMP live range construction after optimization
If we optimize the FREE away, we should switch to constructing
a normal live range, rather than a split live range.

Fixes oss-fuzz #39548.
2021-10-05 11:28:16 +02:00
Nikita Popov
e11faad233 Create reference wrappers in SEND_UNPACK if necessary
Even if we can't actually pass by reference, we still need to
create the REFERENCE wrapper to satisfy the calling convention.
The particular test case would crash with JIT, because the existence
of the reference was assumed.

Fixes oss-fuzz #39440.
2021-09-30 14:55:48 +02:00
Nikita Popov
d0860f67ca Fix cache slot assignment for ASSIGN_OBJ_OP
ASSIGN_OBJ_OP stores the cache slot in OP_DATA, so this ended up
overwriting the binop opcode instread.
2021-09-30 14:34:12 +02:00
Nikita Popov
ec54ffad1e Handle throwing destructor in BIND_STATIC
Fixes oss-fuzz #39406.
2021-09-29 10:17:05 +02:00
Nikita Popov
1bb7ee3207 Fix ASSIGN_DIM result inference with typed refs
Same issue as with ASSIGN. Also make the handling for ASSIGN more
precise, we can only have conversions between scalar values.
2021-09-28 14:14:01 +02:00
Nikita Popov
d8c2ff6486 Fix type inference and SCCP with typed references
We can't assume that the return value will be the same as the RHS
if typed references are involved.
2021-09-28 12:59:00 +02:00
Nikita Popov
17d6efc729 Fix block marking for two arm math
This would end up taking the successors_count=2 case, even though
we need to treat SWITCH and MATCH differently. This incorrectly
marked a block as FOLLOW, resulting in incorrect block pass
optimization.

Fixes oss-fuzz #39380.
2021-09-28 10:37:54 +02:00
Nikita Popov
7d483418e2 Fix relative offsets when copying JMPZNZ
This was doing a plain copy of JMPZNZ, even though it encodes
offsets relative to the opline. As such, the offsets would be
relative to target, while they should be relative to opline.
Fix this by recomputing them.

Fixes oss-fuzz #39295.
2021-09-27 16:18:40 +02:00
Nikita Popov
823888c472 Start block at loop var free
This ensures that code directly before the loop var free is
separated out (and will generally be eliminated as unreachable).
This fixes some assumptions we have that unreachable loop var free
blocks start with the loop var free.

Fixes oss-fuzz #39395.
2021-09-27 11:56:37 +02:00
Nikita Popov
ddf8910237 Fix DCE of unreachable phi in cycle
We can't remove a trivial phi of the form x = phi(x), because we
don't have a replacement value. We could drop the whole block
though. SCCP would normally do this, but in this particular case
we only determine non-reachability based on type information.

Fixes oss-fuzz #39316.
2021-09-27 11:26:31 +02:00
Nikita Popov
038bc27787 Handle pi nodes in replace_predecessor
If we're removing a predecessor because it already exists during
replacement, we should also drop pi nodes for that predecessor.

Fixes oss-fuzz #39276.
2021-09-27 10:47:47 +02:00
Nikita Popov
be8217368b Bail on exception during delayed autoload
We shouldn't try to load further classes if one autoload throws.

This fixes oss-fuzz #38881, though I believe there are still two
deeper issues here: 1) Why do we allow autoloading with an active
exception? 2) Exception save & restore should probably also save
and restore the exception opline.
2021-09-23 12:46:39 +02:00
Nikita Popov
01453a0af7 Fix SEND_USER with ref arg
Even though the input is not a reference (or not treated as such),
we still need to create a reference to satisfy the function
signature. Various code relies on reference arguments actually
being references. In this particular case, it would result in
a JIT crash.

The zend_call_function() implementation already handled this
correctly.
2021-09-17 12:17:33 +02:00
Nikita Popov
5cae6b9b0d Check that POST_INC/DEC has use in DFA optimization
We'd have usually converted it into a PRE_INC if there is no use,
but that's not guaranteed. If there is no use at this point, make
sure we don't try to use the sentinel value.
2021-09-09 15:48:51 +02:00
Nikita Popov
2467f759f5 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix Closure::call() on internal method closure
2021-08-27 11:59:38 +02:00
Nikita Popov
eda9f5f740 Fix Closure::call() on internal method closure
In this case we should use the original internal handler. Otherwise
the trampoline will attempt to free the closure, but the function
being used is not actually part of a closure anymore.
2021-08-27 11:58:13 +02:00
Nikita Popov
6c7b322de2 Fix parameter name in count() error message
This parameter has been renamed to $value.
2021-07-29 14:25:13 +02:00
Nikita Popov
840e441d2d Fix parameter name in call_user_func() error message
This parameter name has been changed to $callback.
2021-07-29 12:48:25 +02:00
Nikita Popov
90ee1c36d7 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix bug #66719
2021-07-23 11:24:59 +02:00
Nikita Popov
dfd05da97f Fix bug #66719
While parent:: should inherit the called scope, it should only do
so if it is compatible. If there is no called scope, or it is not
a subtype of the scope, we should fall back to the scope.
2021-07-23 11:24:22 +02:00
Nikita Popov
567e53ea58 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Undef slot before destroying in unset_property
2021-07-15 09:32:26 +02:00
Nikita Popov
ebd3a21002 Undef slot before destroying in unset_property
We need to make sure that destructors can't access the partially
destroyed property. Do the same we do in HTs.

Fixes oss-fuzz #36205.
2021-07-15 09:31:19 +02:00
Nikita Popov
982c833acd Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Drop incorrect cache_slot optimization for typed properties
2021-07-14 15:10:11 +02:00
Nikita Popov
ba8bcf3992 Drop incorrect cache_slot optimization for typed properties
For a particular assignment, a non-coerced constant assignment
value will remain valid. However, opcache merges cache slots for
all identical property references, which means that this
optimization also disables property type checks for all other
operands on the property that occur in the same functions.

This could be addressed by blocking cache slot merging in opcache,
but I prefer dropping it entirely instead. It does not seem
important enough to warrant doing that.
2021-07-14 15:08:33 +02:00
Nikita Popov
58699ffcf1 Fix constant update for shadowed private property
Updating based on the properties info HT will miss private parent
properties that have been shadowed in the child class. Instead,
perform updating directly on the default properties table.

We can't do the same for static properties, because those don't
have a convenient way to look up the property type from the
property offset. However, I don't believe the problem exists for
static properties, because we're always going to be using the
property on the class it was declared on, while children only hold
INDIRECT references. As such, this should be covered by parent
class const updating.

Fixes oss-fuzz #35906.
2021-07-08 10:12:40 +02:00