Commit Graph

2400 Commits

Author SHA1 Message Date
Nikita Popov
2eb33818b6 Fixed bug #79155
Make sure we only unset the NULLABLE flag temporarily for class
resolution, as the same type may be compiled multiple types.
2020-01-23 12:54:14 +01:00
Dmitry Stogov
d89cd0bb22 Property names of internal classes from temporary extensins, loaded by dl(), may be emalloc-ed strings. 2019-12-17 10:10:11 +03:00
Nikita Popov
0f2cdbf214 Introduce extra counter to avoid RTD key collisions
Also generate a fatal error if a collision occurs in zend_compile.

This is not perfect, because collisions might still be introduced
via opcache, if one file is included multiple times during a request,
invalidate in the meantime and recompiled by different processes.

This still needs to be addressed, but this patch fixes the much
more common case of collisions occuring when opcache is not used.

Fixes bug #78903.
2019-12-13 11:04:44 +01:00
Nikita Popov
be89a5c7f1 Fixed bug #78950: Preloading trait method with static variables
We need to make sure that trait methods with static variables
allocate a separate MAP slot for the static variables pointer,
rather than working in-place.
2019-12-12 11:52:43 +01:00
Nikita Popov
502cd7b1f1 Revert "Fixed bug #78903: Conflict in RTD key for closures results in crash"
This reverts commit b55033fa18.

This breaks ext/opcache/tests/bug65915.phpt.
2019-12-11 14:38:48 +01:00
Nikita Popov
b55033fa18 Fixed bug #78903: Conflict in RTD key for closures results in crash
I wasn't able to create a simple reproducer for this. General approach
is the same as for anonymous classes: If the key is already used, reuse
the old definition.
2019-12-11 13:07:45 +01:00
Dmitry Stogov
20ef51db22 Fixed bug #78937 (Preloading unlinkable anonymous class can segfault) 2019-12-11 00:46:30 +03:00
Nikita Popov
3f86adb0ef Fixed bug #78935: Check that all linked classes can be preloaded
During preloading, check that all classes that have been included
as part of the preload script itself (rather than through opcache_compile_file)
can actually be preloaded, i.e. satisfy Windows restrictions, have
resolved initializers and resolved property types. When resolving
initializers and property types, also autoload additional classes.
Because of this, the resolution runs in a loop.
2019-12-10 13:05:48 +01:00
Nikita Popov
32c1f37574 Fixed bug #78926: Handle class table reallocation on failed link
When we change back the bucket key on a class linking failure,
make sure to reload the bucket pointer, as the class table may
have been reallocated in the meantime.

Also remove a bogus bucket key change in anon class registration:
We don't actually rename the class in this case anymore, the RTD
key is already the final name.
2019-12-09 09:15:27 +01:00
Nikita Popov
07fc0764d1 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix constant evaluation of && and ||
2019-12-06 11:10:31 +01:00
Nikita Popov
249e49092d Fix constant evaluation of && and ||
The "return" in the for loop should have been a break on the switch,
otherwise the result is just ignored... but because it prevents
evaluation of the other operand, it also violates the invariant that
everything has been constant evaluated, resulting in an assertion
failure.

The for loop isn't correct in any case though, because it's not legal
to determine the result based on just the second operand, as the
first one may have a side-effect that cannot be optimized away.
2019-12-06 11:07:57 +01:00
Dmitry Stogov
c3f23642da ws 2019-11-12 10:51:55 +03:00
Nikita Popov
bea832cbf6 Don't check type of simple parameter default values
After fixing the int->double coercion case, this is already verified
at compile-time, so there is no need to redo this type check on
every call.

Only perform the type check every time for the case of AST default
values.
2019-10-08 17:29:41 +02:00
Nikita Popov
9004102b99 Fixed bug #78648 2019-10-08 15:39:22 +02:00
Nikita Popov
b078ae6c01 Merge branch 'PHP-7.3' into PHP-7.4 2019-10-04 22:46:53 +02:00
Nikita Popov
239e2dda64 Make sure T_ERROR is returned for all lexer exceptions
This originally manifested as a leak in oss-fuzz #18000. The following
is a reduced test case:

    <?php
    [
        5 => 1,
        "foo" > 1,
        "      " => "" == 0
    ];
    <<<BAR
    $x
     BAR;

Because this particular error condition did not return T_ERROR,
EG(exception) was set while performing binary operation constant
evaluation, which checks exceptions for cast failures.

Instead of adding this indirect test case, I'm adding an assertion
that the lexer has to return T_ERROR if EG(exception) is set.
2019-10-04 22:42:14 +02:00
Nikita Popov
9659562cb5 Fix use-after-free with delayed interned memoized const operand
We should addref CONST operands during memoization, as they might
be destroyed by later compilation, e.g. through interning.
2019-10-04 10:38:11 +02:00
Nikita Popov
f26b60a583 Fix crash when unpacking into array literal with string keys 2019-10-04 10:11:30 +02:00
Nikita Popov
171d6c3ca7 Merge branch 'PHP-7.3' into PHP-7.4 2019-10-02 12:07:33 +02:00
Nikita Popov
3c42471ef8 Merge branch 'PHP-7.2' into PHP-7.3 2019-10-02 12:07:19 +02:00
Nikita Popov
a5d3620d93 Fix segfault with __COMPILER_HALT_OFFSET__ and trailing {}
Fixes OSS-Fuzz #17895.
2019-10-02 12:07:15 +02:00
Nikita Popov
4226c8247f Fix use-after-free in assign-ref compilation
zend_emit_op_data may reallocate the op_array, so the assignment
of the RETURNS_FUNCTION flag may happen on an outdated opline.

Restructure the code a bit to set the flag before calling
zend_emit_op_data().
2019-09-13 18:22:14 +02:00
Dmitry Stogov
e45a757bc2 Fixed incorrect usage of QM_ASSIGN instruction 2019-09-13 12:08:59 +03:00
Nikita Popov
4b9ebd837b Allow throwing exception while loading parent class
This is a fix for symfony/symfony#32995.

The behavior is:

* Throwing exception when loading parent/interface is allowed
  (and we will also throw one if the class is simply not found).
* If this happens, the bucket key for the class is reset, so
  it's possibly to try registering the same class again.
* However, if the class has already been used due to a variance
  obligation, the exception is upgraded to a fatal error, as we
  cannot safely unregister the class stub anymore.
2019-09-12 16:41:18 +02:00
Nikita Popov
d88b212ea6 Improve "already declared" error message
If this error is missing because the rtd_key was renamed to lcname,
fetch the class based on lcname and use the class type and cased
name from there.
2019-09-11 17:04:13 +02:00
Nikita Popov
e81751ceac Fixed bug #78502
We need to make sure that the function is fully compiled before we
calculate the stack size. There already was a check for directly
recursive calls, but the same issue exists with indirectly recursive
calls.

I'm using DONE_PASS_TWO as the indication that the function is
fully compiled.
2019-09-06 11:33:28 +02:00
Nikita Popov
d1157cbce1 Relax closure $this unbinding deprecation
Only deprecate unbinding of $this from a closure if $this is
syntactically used within the closure.

This is desired to support Laravel's macro system, see laravel/framework#29482.

This should still allow us to implement the performance improvements
we're interested in for PHP 8, without breaking existing use-cases.
2019-08-23 17:21:23 +02:00
Nikita Popov
b6f1b61f8f Merge branch 'PHP-7.3' into PHP-7.4 2019-08-12 17:17:42 +02:00
Nikita Popov
4cd563d07e Merge branch 'PHP-7.2' into PHP-7.3 2019-08-12 17:17:30 +02:00
Nikita Popov
f3fdf570b3 Intern alias old_name early
This is likely going to end up interned lateron at some point
when the new_name is referenced somewhere. However, it may be
that there are some uses that do not get interned before that.
In this case we will intern a string that already have zval
users, without updating the refcounted flag on those zvals.

In particular this can happen with something like [Foo::class],
where Foo is an imported symbol. The string it resolves to won't
get interned right away, but may be interned later.

    use Foo as Bar;
    $x = [Bar::class];
    var_dump(Bar::X);
    debug_zval_dump($x); // Will show negative refcount
    class Foo {
        const X = 1;
    }

However, this doesn't really fix the root cause, there are probably
other situations where something similar can occur.
2019-08-12 17:12:28 +02:00
Nikita Popov
afd96392a3 Revert "Use RW fetch for argument unpacking"
This reverts commit 6913ec3282.
This reverts commit a9e332e027.

Causes https://bugs.php.net/bug.php?id=78356, which I don't have
a good solution for.
2019-08-01 10:06:53 +02:00
Nikita Popov
6913ec3282 Use RW fetch for argument unpacking
Argument unpacking may need to create references inside the array
that is being unpacked. However, it currently can only do this
if a plain variable is unpacked, not for any nested accesses,
because the value is fetched for read. Resolve this by fetching
the operands for RW.
2019-07-30 10:07:08 +02:00
Nikita Popov
4ae807e84e Fixed bug #78344
When performing a constant visibility check during compilation we
might be dealing with unlinked classes and as such should account
for the possibility of unresolved parents.
2019-07-29 11:12:00 +02:00
Nikita Popov
4e190691e2 Deprecate is_real() function 2019-07-22 11:39:52 +02:00
Dmitry Stogov
445d51347d Use run-time cache to avoid repeatable hash lookups in ZEND_DECLARE_CLASS_DELAYED 2019-07-19 11:46:03 +03:00
rjhdby
d574df63dc Deprecate alternative array access syntax
RFC: https://wiki.php.net/rfc/deprecate_curly_braces_array_access
2019-07-19 10:06:10 +02:00
Dmitry Stogov
d5943f5a11 Use run-time cache to avoid repeatable hash lookups when creating anonymous functions and classes 2019-07-19 10:43:49 +03:00
Dmitry Stogov
b065fbde19 ZEND_DECLARE_ANON_CLASS doesn't need to skip anything now. It's immediatelly followed by ZEND_NEW. 2019-07-19 10:09:26 +03:00
Nikita Popov
c5f1b384b5 Move shebang handling into the lexer
Instead of handling shebang lines by adjusting the file pointer in
individual SAPIs, move the handling into the lexer, where this is
both a lot simpler and more robust. Whether the shebang should be
skipped is controlled by CG(skip_shebang) -- we might want to do
that in more cases.

This fixed bugs #60677 and #78066.
2019-07-15 16:25:49 +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
Nikita Popov
9f81c56e42 Fix out-of-bounds read in array compilation
UNPACK elements only have one child. Don't access the second one
until we have excluded this case.
2019-06-28 12:44:46 +02:00
Dmitry Stogov
83b99527df Avoid double checks on early binding 2019-06-27 02:13:06 +03:00
Dmitry Stogov
1d534b9da5 Set ZEND_ACC_LINKED flag after early binding (for consistency) 2019-06-25 15:05:27 +03:00
Dmitry Stogov
e8f1f70101 Reduce overhead of delayed early binding 2019-06-25 14:20:41 +03:00
Dmitry Stogov
759f4ecd8b Keep lowercased parent class name as second argument of DECLARE_CLASS to avoid extra work at run-time 2019-06-25 11:30:58 +03:00
Dmitry Stogov
0f29fb5cd8 Fixed bug 78175 (Preloading must store default values of static variables and properties) 2019-06-24 20:32:27 +03:00
Nikita Popov
f601eb15e6 Fix -Wmissing-braces warnings
Unfortunate that = {} is a GNU extension.
2019-06-12 11:54:12 +02:00
Nikita Popov
8f8fcbbd39 Support full variance if autoloading is used
Keep track of delayed variance obligations and check them after
linking a class is otherwise finished. Obligations may either be
unresolved method compatibility (because the necessecary classes
aren't available yet) or open parent/interface dependencies. The
latter occur because we allow the use of not fully linked classes
as parents/interfaces now.

An important aspect of the implementation is we do not require
classes involved in variance checks to be fully linked in order for
the class to be fully linked. Because the involved types do have to
exist in the class table (as partially linked classes) and we do
check these for correct variance, we have the guarantee that either
those classes will successfully link lateron or generate an error,
but there is no way to actually use them until that point and as
such no possibility of violating the variance contract. This is
important because it ensures that a class declaration always either
errors or will produce an immediately usable class afterwards --
there are no cases where the finalization of the class declaration
has to be delayed until a later time, as earlier variants of this
patch did.

Because variance checks deal with classes in various stages of
linking, we need to use a special instanceof implementation that
supports this, and also introduce finer-grained flags that tell us
which parts have been linked already and which haven't.

Class autoloading for variance checks is delayed into a separate
stage after the class is otherwise linked and before delayed
variance obligations are processed. This separation is needed to
handle cases like A extends B extends C, where B is the autoload
root, but C is required to check variance. This could end up
loading C while the class structure of B is in an inconsistent
state.
2019-06-11 13:09:33 +02:00
Nikita Popov
89b2d88659 Register class before fetching parent
We want the class declaration to be available while compiling the
parent class.
2019-06-11 13:09:33 +02:00
Joe Watkins
42d60addef
BIND_LEXICAL has a meaningless line number 2019-06-10 14:19:39 +02:00