Commit graph

2949 commits

Author SHA1 Message Date
Gina Peter Banyard
65d433161a
Use new known "self" and "parent" zend_strings (#17766) 2025-02-12 15:30:55 +00:00
Gina Peter Banyard
1ad7743133
Zend: Resolve self and parent types at compile time (#17755)
This does not apply to traits.
2025-02-11 15:15:32 +00:00
Ilija Tovilo
fa7c67d622
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix stack overflow detection for variable compilation
2025-01-29 23:28:22 +01:00
Ilija Tovilo
4f91af38cc
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix stack overflow detection for variable compilation
2025-01-29 23:28:16 +01:00
Ilija Tovilo
333f5dd848
Fix stack overflow detection for variable compilation
Closes GH-17623
2025-01-29 23:27:27 +01:00
Niels Dossche
75bd1a9dc0
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix may_have_extra_named_args flag for ZEND_AST_UNPACK
2025-01-21 19:27:24 +01:00
Niels Dossche
0b12db6afa
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix may_have_extra_named_args flag for ZEND_AST_UNPACK
2025-01-21 19:27:19 +01:00
Niels Dossche
0b3e637aec
Fix may_have_extra_named_args flag for ZEND_AST_UNPACK
The check for `!fbc || (fbc->common.fn_flags & ZEND_ACC_VARIADIC)` is
performed after `fbc` is set to NULL, so this always returns true.
This results in `ZEND_FCALL_MAY_HAVE_EXTRA_NAMED_PARAMS` always being
set for unpack sends. Fix it by moving the flag updates to the point
before setting `fbc` to NULL.

Closes GH-17534.
2025-01-21 19:26:49 +01:00
Ilija Tovilo
e95b298262
Store prop info name in CG(context) instead of prop info
The prop info is not always available, e.g. when compiling the default
value.

See GH-17378
Closes GH-17464
2025-01-14 17:01:10 +01:00
Ilija Tovilo
a06668af30
Merge branch 'PHP-8.4'
* PHP-8.4:
  __PROPERTY__ does not work in all constant expression contexts
2025-01-13 16:43:32 +01:00
Ilija Tovilo
147e9c808c
__PROPERTY__ does not work in all constant expression contexts
Fixes GH-17222
Closes GH-17378
2025-01-13 16:42:38 +01:00
Tim Düsterhus
cee64ed3bd
Add dedicated zend_ast_op_array struct (#17391)
Given that the `ZEND_AST_OP_ARRAY` type already needed special handling in
various places, it makes sense to give it its own struct to avoid some of the
casts. As a side benefit, it is a little smaller than the `zend_ast_zval`
struct.
2025-01-08 11:26:35 +01:00
Tim Düsterhus
fd1eacc2ed
Add assertions verifying that zend_ast_decl AST nodes are not treated as regular zend_ast nodes (#17390)
* zend_compile: Do not traverse children of ZEND_AST_CLOSURE in zend_compile_const_expr()

* Add assertions verifying that zend_ast_decl AST nodes are not treated as regular zend_ast nodes
2025-01-08 10:36:02 +01:00
Niels Dossche
cc4402b6cb
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17234: Numeric parent hook call fails with assertion
2025-01-07 19:21:35 +01:00
Niels Dossche
71493623f4
Fix GH-17234: Numeric parent hook call fails with assertion
The current code expects the property name to be a string, but it can
also be a number via the {} syntax. Handle this consistently to a string
by using zval_get_string which will do the type coercion and refcount
update (instead of assuming string and doing an explicit string copy).

Closes GH-17236.
2025-01-07 19:21:22 +01:00
Ilija Tovilo
fbb97aa6fc
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix unstable get_iterator pointer for hooked classes in shm on Windows
2024-12-09 17:14:46 +01:00
Ilija Tovilo
792f63df45
Fix unstable get_iterator pointer for hooked classes in shm on Windows
Closes GH-17034
2024-12-09 17:14:19 +01:00
Tim Düsterhus
f6a0bb4d04
Support Closures in constant expressions (#16458)
RFC: https://wiki.php.net/rfc/closures_in_const_expr

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Arthur Kurbidaev <artkurbidaev@gmail.com>
2024-12-02 18:25:43 +01:00
Christoph M. Becker
fdd3839d80
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix potential OOB read in zend_dirname() on Windows
2024-11-29 22:11:27 +01:00
Christoph M. Becker
ba7dee5676
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix potential OOB read in zend_dirname() on Windows
2024-11-29 22:11:00 +01:00
Christoph M. Becker
65070bb46c
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix potential OOB read in zend_dirname() on Windows
2024-11-29 22:09:40 +01:00
Christoph M. Becker
94fa2a4ce1
Fix potential OOB read in zend_dirname() on Windows
Only on Windows `IS_SLASH_P()` may read the previous byte, and so may
in unlikely cases read one byte out of bounds.  Since `IS_SLASH_P()` is
in a public header (albeit not likely to be used by external extensions
or SAPIs), we introduce `IS_SLASH_P_EX()` which accepts a second
argument to prevent that OOB read.

It should be noted that the PHP userland function `dirname()` is not
affected by this issue, since it does not call `zend_dirname()` on
Windows.

Closes GH-16995.
2024-11-29 22:08:06 +01:00
Ilija Tovilo
f44eaac48a
Simplify duplicate member flag check (GH-16874) 2024-11-21 14:54:57 +01:00
Niels Dossche
dfba04e807
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-16727: Opcache bad signal 139 crash in ZTS bookworm (frankenphp)
2024-11-11 16:20:44 +01:00
Niels Dossche
382be923ae
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16727: Opcache bad signal 139 crash in ZTS bookworm (frankenphp)
2024-11-11 16:20:39 +01:00
Niels Dossche
fbf4cec63b
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16727: Opcache bad signal 139 crash in ZTS bookworm (frankenphp)
2024-11-11 16:20:30 +01:00
Niels Dossche
02ee521e20
Fix GH-16727: Opcache bad signal 139 crash in ZTS bookworm (frankenphp)
Reproducer: https://github.com/php/php-src/issues/16727#issuecomment-2466256317

The root cause is a data race between two different threads:

1) We allocate a lower cased name for an anonymous class here:
   f97353f228/Zend/zend_compile.c (L8109)
2) This gets looked up as an interned string here:
   f97353f228/Zend/zend_compile.c (L8112)
   Assuming that there are uppercase symbols in the string and therefore
   `lcname != name` and that `lcname` is not yet in the interned string table,
   the pointer value of `lcname` won't change.
3) Here we add the string into the interned string table:
   f97353f228/Zend/zend_compile.c (L8223)
   However, in the meantime another thread could've added the string into the interned string table.
   This means that the following code will run, indirectly called via the `LITERAL_STR` macro,
   freeing `lcname`: 62e53e6f49/ext/opcache/ZendAccelerator.c (L572-L575)
4) In the reproducer we then access the freed `lcname` string here:
   f97353f228/Zend/zend_compile.c (L8229)

This is solved in my patch by retrieving the interned string pointer
and putting it in `lcname`.

Closes GH-16748.
2024-11-11 16:20:05 +01:00
Niels Dossche
96d1cd00b7
Fix GH-16665: \array and \callable should not be usable
This list was initially introduced in 53a40386, but never included array or
callable. I suppose this is because int & friends are not actual tokens,
while array and callable are. This means it was never possible to do class
array, which is probably the reason this was overlooked.

Closes GH-16683.
2024-11-06 18:16:06 +01:00
Christoph M. Becker
91e6f2621c
Add sanitity checks regarding num_args and arg_info (GH-16538)
`num_args > 0` implies that `arg_info != NULL`.  We explicitly assert
that during compilation and execution to make it easier for developers
to not miss this[1].

[1] <https://github.com/php/php-src/issues/16266>
2024-10-25 15:52:53 +02:00
DanielEScherzer
0b94cf65e4
GH-16067: prevent invalid abstract during compilation of methods (GH-16069)
For classes that are not declared `abstract`, produce a compiler error for any
`abstract` methods. For anonymous classes, since they cannot be made abstract,
the error message is slightly different.

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2024-10-23 15:04:18 +02:00
Ilija Tovilo
cd8ee4dad1
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix lineno in function redeclaration error
2024-10-22 15:06:06 +02:00
Ilija Tovilo
381e020edb
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix lineno in function redeclaration error
2024-10-22 15:05:29 +02:00
Ilija Tovilo
de7ef3fa66
Fix lineno in function redeclaration error
We were previously using the lineno of the first instruction, rather than the
start of the function itself.

Fixes GH-16509
Closes GH-16531
2024-10-22 15:04:20 +02:00
Ilija Tovilo
a8bbc84551
Disallow asymmetric visibility on static properties
This check was forgotten in the original implementation. Relaxing this
restriction shouldn't be hard, but needs some work. We either need to prevent
merging of cache slots for R/RW/W, or we need to introduce an additional check
when writing to the property indirectly. This check is currently present only
for direct writes.

Closes GH-16462
2024-10-16 23:00:11 +02:00
DanielEScherzer
702fb31894
zend_resolve_const_class_name_reference(): use double quotes around names (#15998)
This is a follow-up to #15990, as it turns out there was a second place that emits this kind of error message.
2024-09-23 09:59:48 +01:00
DanielEScherzer
34325c5e3a
zend_assert_valid_class_name(): use double quotes around names (#15990) 2024-09-23 00:44:16 +01:00
Daniel Scherzer
79d708cfca GH-15976: clarify error messages for enum/trait/interface/alias names
Instead of always saying that a name is reserved or deprecated and
cannot/should not be used as a class name, take the usage into account and say
the name cannot be used as an enum name, trait name, etc. In the process, for
class names add a missing "a".
2024-09-22 19:14:57 +01:00
Jorg Adam Sowa
2a30f2ffc4
Add type indicator to array/arg unpack error messages (GH-15448) 2024-09-01 22:57:12 +02:00
Ilija Tovilo
8df557ac42
[RFC] Asymmetric visibility v2 (GH-15063)
Co-authored-by: Larry Garfield <larry@garfieldtech.com>
2024-08-27 02:04:48 +02:00
Gina Peter Bnayard
5853cdb73d Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
Ilija Tovilo
36b1977415
Fix missing compile error when declaring hooked props on readonly classes (GH-15439)
Fixes GH-15419
2024-08-19 14:58:55 +02:00
Ilija Tovilo
770616b823
Fix param with hooks but no visibility not treated as cpp (GH-15442)
Fixes GH-15438
2024-08-19 14:53:54 +02:00
Gina Peter Banyard
a79c70f574
[RFC] Convert exit (and die) from language constructs to functions (#13483)
RFC: https://wiki.php.net/rfc/exit-as-function
2024-08-14 12:44:12 +01:00
Ilija Tovilo
be6dee3c5d
Reset seen symbols when ending namespace (GH-15244)
Previously, seen symbols were never cleaned during the compilation of a single
file. This makes it impossible to use a class or function from a different
namespace if such a symbol is also declared within the same file. This is
inconsistent with how it would work when split into different files.
2024-08-13 15:47:14 +02:00
Ilija Tovilo
a4772a0c47
[skip ci] Remove unclosed vim code folding 2024-08-12 18:50:38 +02:00
Gina Peter Banyard
0a23b0678d
Deprecate using "_" as a class name (#15360)
RFC: https://wiki.php.net/rfc/deprecations_php_8_4#deprecate_using_a_single_underscore_as_a_class_name
2024-08-12 16:10:30 +01:00
Ilija Tovilo
50217b35ea
Remove IS_STATIC_VAR_UNINITIALIZED (#15227)
This flag was never necessary. We know a static variable is uninitialized (i.e.
the initializer has never been called) iff the zval in the static variable array
does not contain a reference.

Prompted by a related issue in ext-uopz reported by Christoph.
2024-08-05 11:19:13 +02:00
Tim Düsterhus
551038bb16
zend_compile: Fully remove ZEND_DIM_ALTERNATIVE_SYNTAX (#14974)
This flag is longer set since the merge of property hooks in
780a8280d2. This patch removes it completely,
because the corresponding error messages are unreachable.
2024-07-16 16:27:46 +02:00
Ilija Tovilo
780a8280d2
[RFC] Property hooks (#13455)
RFC: https://wiki.php.net/rfc/property-hooks

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2024-07-14 11:55:03 +02:00
Arnaud Le Blanc
0bd260218b
Fix stack limit on ASAN/MSAN (#14771)
Increase the reserved stack size in ASAN builds, as instrumentation use more stack.
Increase the max allowed stack size in some tests, and enable these tests under ASAN.
Use __builtin_frame_address(0), instead of some stack variable, when we need a stack address, as ASAN may store local variables outside of the real stack.
2024-07-03 19:23:34 +02:00