Commit Graph

2870 Commits

Author SHA1 Message Date
Ilija Tovilo
3d86d9acc1
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Add missing COMPILE_IGNORE_OTHER_FILES check for static calls
2024-04-17 22:39:48 +02:00
Ilija Tovilo
1acd7a0919
Add missing COMPILE_IGNORE_OTHER_FILES check for static calls
Closes GH-13986
2024-04-17 22:39:05 +02:00
Arnaud Le Blanc
6aa70b577d WS 2023-12-10 13:24:49 +01:00
Arnaud Le Blanc
b1516d95e0 Clarify the stack limit exception message
Make it clearer why the size is not exactly zend.max_allowed_stack_size
2023-12-10 13:20:21 +01:00
Ilija Tovilo
4ba5699903
Fix invalid returned opcode for memoized expressions
Closes GH-12345
2023-10-03 14:01:43 +02:00
Ilija Tovilo
011071a3b3
Improve invalid cpp modifier message
The ZEND_MODIFIER_TARGET_CPP should really have been called _PARAM, but we
shouldn't break API at this point.

Fixes GH-12069
Closes GH-12175
2023-09-11 16:23:43 +02:00
Ilija Tovilo
c2bb9bc0df
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix zend_separate_if_call_and_write for FUNC_ARGs
2023-09-07 14:26:09 +02:00
Ilija Tovilo
fa9cef8b47
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix zend_separate_if_call_and_write for FUNC_ARGs
2023-09-07 14:25:43 +02:00
Ilija Tovilo
748adf18fc
Fix zend_separate_if_call_and_write for FUNC_ARGs
Fixes GH-12102
Closees GH-12140
2023-09-07 14:25:11 +02:00
Cristian Rodríguez
782ffd761b
Use a single version of strnlen (#12015)
* Zend: Make zend_strnlen available for use outside zend_compile

* exif: remove local php_strnlen, use zend_strnlen instead

* main: remove local strnlen, use zend_strnlen instead

* phar: remove local strnlen, use zend_strnlen
2023-08-22 17:40:24 +02:00
ju1ius
7f1c3bf09b
Adds support for DNF types in internal functions and properties (#11969)
Note that this does not add support for items generated by gen_stubs,
only for items registered dynamically via the Zend API.

Closes GH-10120
2023-08-19 00:11:06 +01:00
Ilija Tovilo
1b9ff16f92
Merge branch 'PHP-8.2'
* PHP-8.2:
  Remove redundant condition
2023-08-17 18:55:51 +02:00
Ilija Tovilo
d016c49cf5
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Remove redundant condition
2023-08-17 18:55:45 +02:00
Ilija Tovilo
dd01c74a6f
Remove redundant condition
Never refactor code just before pushing
2023-08-17 18:54:30 +02:00
Ilija Tovilo
48ede64506
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix segfault in format_default_value due to unexpected enum/object
2023-08-17 18:44:37 +02:00
Ilija Tovilo
9437aa9a8e
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix segfault in format_default_value due to unexpected enum/object
2023-08-17 18:43:49 +02:00
Ilija Tovilo
f78d1d0d10
Fix segfault in format_default_value due to unexpected enum/object
Evaluating constants at comptime can result in arrays that contain objects. This
is problematic for printing the default value of constant ASTs containing
objects, because we don't actually know what the constructor arguments were.
Avoid this by not propagating array constants.

Fixes GH-11937
Closes GH-11947
2023-08-17 18:43:11 +02:00
Ilija Tovilo
db4dba6702
Move opnum_start for goto for clarification (#11911)
opnum_start denotes the start of the ZEND_FREE block of skipped consuming
opcodes. Storing the number before zend_compile_expr(..., label_ast) makes it
seem like it denotes the start of the label block. However, label_ast must only
be a zval string AST, and as such never results in an actual opcode.
2023-08-09 11:38:54 +02:00
Ilija Tovilo
1057cce1c0
Always memoize calls in lhs of coalesce assignment
We don't want to invoke calls twice, even if they are considered "variables",
i.e. might be writable if returning a reference. Function calls behave the same
in all BP contexts so they don't need to be invoked twice. The singular
exception to this is nullsafe coalesce in isset/empty, because it needs to
return false/true respectively when short-circuited. However, since nullsafe
calls are not allwed in write context we may ignore this problem.

Closes GH-11592
2023-07-18 12:48:00 +02:00
George Peter Banyard
3e2dbbf9c2 Add support for deprecating class constants 2023-07-17 05:01:13 +01:00
Ilija Tovilo
c1a7058e66
Merge branch 'PHP-8.2'
* PHP-8.2:
  Always memoize assert
2023-07-12 16:36:14 +02:00
Ilija Tovilo
6d98c085a1
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Always memoize assert
2023-07-12 16:36:08 +02:00
Ilija Tovilo
b1b7c61a27
Always memoize assert
Closes GH-11686
2023-07-12 16:35:09 +02:00
Ilija Tovilo
a833937725
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix double-compilation of arrow-function
2023-07-12 11:01:38 +02:00
Ilija Tovilo
060df83a98
Fix double-compilation of arrow-function
We transform the arrow function by nesting the expression into a return
statement. If we compile the arrow function twice this would be done twice,
leading to a compile assertion.

Fix oss-fuzz #60411
Closes GH-11632
2023-07-12 11:01:23 +02:00
Arnaud Le Blanc
72a163aa90
Add stack limit check in zend_eval_const_expr() (#11424) 2023-07-07 14:18:15 +02:00
Ilija Tovilo
dbbcbcb5b5
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix use-of-uninitialized-value with ??= on assert
2023-07-06 09:39:46 +02:00
Ilija Tovilo
ac3ff5bb7a
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix use-of-uninitialized-value with ??= on assert
2023-07-06 09:39:05 +02:00
Ilija Tovilo
84a2e48050
Fix use-of-uninitialized-value with ??= on assert
Normally, PHP evaluates all expressions in offsets (property or array), as well
as the right hand side of assignments before actually fetching the offsets. This
is well explained in this blog post.

https://www.npopov.com/2017/04/14/PHP-7-Virtual-machine.html#writes-and-memory-safety

For ??= we have a bit of a problem in that the rhs must only be evaluated if the
lhs is null or undefined. Thus, we have to first compile the lhs with BP_VAR_IS,
conditionally run the rhs and then re-fetch the lhs with BP_VAR_W to to make
sure the offsets are valid if they have been invalidated.

However, we don't want to just re-evaluate the entire lhs because it may contain
side-effects, as in $array[$x++] ??= 42;. In this case, we don't want to
re-evaluate $x++ because it would result in writing to a different offset than
was previously tested. The same goes for function calls, like
$array[foo()] ??= 42;, where the second call to foo() might result in a
different value. PHP behaves correctly in these cases. This is implemented by
memoizing sub-expressions in the lhs of ??= and reusing them when compiling the
lhs for the second time. This is done for any expression that isn't a variable,
i.e. anything that can (potentially) be written to.

Unfortunately, this also means that function calls are considered writable due
to their return-by-reference semantics, and will thus not be memoized. The
expression foo()['bar'] ??= 42; will invoke foo() twice. Even worse,
foo(bar()) ??= 42; will call both foo() and bar() twice, but
foo(bar() + 1) ??= 42; will only call foo() twice. This is likely not by design,
and was just overlooked in the implementation. The RFC does not specify how
function calls in the lhs of the coalesce assignment behaves. This should
probably be improved in the future.

Now, the problem this commit actually fixes is that ??= may memoize expressions
inside assert() function calls that may not actually execute. This is not only
an issue when using the VAR in the second expression (which would usually also
be skipped) but also when freeing the VAR. For this reason, it is not safe to
memoize assert() sub-expressions.

There are two possible solutions:

1. Don't memoize any sub-expressions of assert(), meaning they will execute
   twice.
2. Throw a compile error.

Option 2 is not quite simple, because we can't disallow all memoization inside
assert(), as that would break assertions like assert($array[foo()] ??= 'bar');.
Code like this is highly unlikely (and dubious) but possible. In this case, we
would need to make sure that a memoized value could not be used across the
assert boundary it was created in. The complexity for this is not worthwhile. So
we opt for option 1 and disable memoization immediately inside assert().

Fixes GH-11580
Closes GH-11581
2023-07-06 09:38:41 +02:00
Ilija Tovilo
80873d28b1
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix trailing if element JMP lineno
2023-07-05 21:04:45 +02:00
Ilija Tovilo
a5e89c5686
Fix trailing if element JMP lineno
Having this lineno on the same last compiled element can lead to an incorrectly
covered line number.

if (true) {
    if (false) {
        echo 'Never executed';
    }
} else {
}

The echo will be reported as covered because the JMP from the if (true) branch
to the end of the else branch has the same lineno as the echo.

This is lacking a test because zend_dump.c does not have access to
ctx->debug_level and I don't think it's worth adjusting all the cases.

Closes GH-11598
2023-07-05 21:04:11 +02:00
Tim Düsterhus
49ef6e209d
RFC: Add #[Override] attribute (#9836)
* Add #[Override] attribute

* Move #[\Override] tests into Zend/tests/attributes/override/

* Check `check_only` before removing `ZEND_ACC_OVERRIDE`

* NEWS/UPGRADING for #[\Override]
2023-06-29 20:23:53 +02:00
Ilija Tovilo
68ef3938f4
Fix missing "Optional parameter before required" deprecation on union null type
The check would only work for the ?type syntax, but not  type|null. Switch to a
check during type compilation instead.

Fixes GH-11488
Closes GH-11497
2023-06-28 20:45:43 +02:00
Ilija Tovilo
a94216dcb7
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix mis-compilation of by-reference nullsafe operator
2023-06-28 20:37:25 +02:00
Ilija Tovilo
54dfa86728
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix mis-compilation of by-reference nullsafe operator
2023-06-28 20:36:30 +02:00
Ilija Tovilo
dc73b73f8b
Fix mis-compilation of by-reference nullsafe operator
Fixes oss-fuzz #60011
Closes GH-11540

Co-authored-by: Dmitry Stogov <dmitry@zend.com>
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2023-06-28 20:35:29 +02:00
Ilija Tovilo
fae42c8bd8
Fix assertion violation for invalid class const objects in const expressions (#11458)
Fixes oss-fuzz #59764
2023-06-21 14:59:05 +02:00
George Peter Banyard
d5ad75108e
More usage of known zend_str instead of C string (#11381) 2023-06-08 13:03:29 +01:00
Niels Dossche
79d024ac0e
Allow final modifier when using a method from a trait (#11394)
Fixes GH-11388.

Following https://wiki.php.net/rfc/horizontalreuse which introduced traits,
this should be allowed.
The implementation was refactored in 3f8c729. That commit is the first time
the "final" check appears AFAICT, but no reason was given for why. That
commit seems to have landed in 5.4.11 and the NEWS for that version doesn't
seem to mention something relevant to the behaviour change.
This patch removes the restriction of the final modifier.

Closes GH-11394.
2023-06-07 23:53:21 +02:00
Ilija Tovilo
fbe6696d49 Revert "Use zend_ast_apply in zend_eval_const_expr (#11261)"
This reverts commit 1c733c8bbc.

Fixes GH-11320
2023-05-26 12:15:01 +02:00
Ilija Tovilo
0b1d750d91
Allow arbitrary expressions in static variable initializer
Closes GH-9301
2023-05-24 20:17:31 +02:00
Ilija Tovilo
1c733c8bbc
Use zend_ast_apply in zend_eval_const_expr (#11261)
Supporting new constant expressions requires remembering to add them to
zend_eval_const_expr, even if it only evalutes its children. This is routinely
forgotten, at least by me. Use zend_ast_apply to solve this generically.
2023-05-24 16:35:37 +02:00
Nikita Popov
c230aa9be3 Correctly handle multiple constants in typed declaration
While here also fix AST printing support.
2023-05-21 14:17:01 +01:00
Ilija Tovilo
0600f513b3
Implement delayed early binding for classes without parents
Normally, we add classes without parents (and no interfaces or traits) directly
to the class map, early binding the class. However, if the same class has
already been registered, we would instead just add a ZEND_DECLARE_CLASS
instruction and let the handler throw a duplicate class declaration exception.

However, with opcache, if on the next request the files are included in the
opposite order, we won't perform early binding. To fix this, create a
ZEND_DECLARE_CLASS_DELAYED instruction instead and handle classes without
parents accordingly, skipping any linking for classes that are already linked in
delayed early binding.

Fixes GH-8846
2023-05-15 10:25:33 +02:00
Ilija Tovilo
4f74e8672c
Merge branch 'PHP-8.2'
* PHP-8.2:
  Allow aliasing namespaces containing reserved class names
2023-04-30 13:44:58 +02:00
Ilija Tovilo
5ad6571a21
Allow aliasing namespaces containing reserved class names
This reverts commit b9f7123c5e.

Fixes GH-11152
Closes GH-11153
2023-04-30 13:44:34 +02:00
Máté Kocsis
414f71a902
Typed class constants (#10444)
RFC: https://wiki.php.net/rfc/typed_class_constants

Co-Authored-By: Ben <7127204+moliata@users.noreply.github.com>
Co-Authored-By: Bob Weinand <3154871+bwoebi@users.noreply.github.com>
Co-Authored-By: Ilija Tovilo <ilija.tovilo@me.com>
2023-04-16 22:20:26 +02:00
Ilija Tovilo
c4a1100f19
Fix unevaluated rhs of class constant fetch in constant expression (#11047)
Fixes oss-fuzz #57821
2023-04-10 16:41:43 +02:00
Niels Dossche
3ab6e76ed8 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-10983: State-dependant segfault in ReflectionObject::getProperties
  Fix GH-10990: mail() throws TypeError after iterating over $additional_headers array by reference
  Fix GH-8841: php-cli core dump calling a badly formed function
2023-04-01 20:23:57 +02:00
Niels Dossche
0d12b3db64 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10990: mail() throws TypeError after iterating over $additional_headers array by reference
  Fix GH-8841: php-cli core dump calling a badly formed function
2023-04-01 20:04:48 +02:00