Commit graph

18977 commits

Author SHA1 Message Date
Niels Dossche
d11f9717fd
zend_alloc: Fix compile with ZEND_MM_STAT=0
Closes GH-18811.
2025-06-09 17:27:39 +02:00
Daniil Gentili
9a9d98e02f
Do not delete main chunk in zend_gc
Closes GH-18756.

Co-authored-by: Arnaud Le Blanc <arnaud.lb@gmail.com>
2025-06-09 11:23:29 +02:00
Niels Dossche
4162c20787
Fix compile without ZEND_MM_STORAGE 2025-06-05 21:51:30 +02:00
Oleg Efimov
087f38f347
Fix GH-18695: float numbers zero fraction is now preserved in zend_ast_export() (#18699) 2025-05-29 13:46:11 -07:00
Máté Kocsis
772479ea2f
Fix build on Apple Clang 17+ (#18629)
Fixing "invalid cpu feature string for builtin" errors that started to appear on Apple Clang 17.0.0
2025-05-24 22:26:06 +02:00
Jakub Zelenka
8e2c2be7a5
PHP-8.3 is now for PHP 8.3.23-dev 2025-05-21 00:39:56 +02:00
Niels Dossche
98cb17f4fd
Fix OSS-Fuzz #418106144
The VM assumes that an exception must be handled when the AST evaluation
returns FAILURE. However, the comparison functions always return SUCCESS
even if an exception happened. This can be fixed in
zend_ast_evaluate_inner() or we can make is_smaller_function() etc check
for the exception. I chose the former to avoid impact or API breaks.
Perhaps in the future the comparison functions should either return void
or return whether an exception happened, as to be not misleading.

Closes GH-18589.
2025-05-19 19:05:32 +02:00
Niels Dossche
46ac878f6a
Fix OSS-Fuzz #417078295
If the variable_ptr and fetched value are the same or overlap, then we
get a UAF. Prevent this by delaying destruction.

Closes GH-18588.
2025-05-19 19:04:58 +02:00
Levi Morrison
35455b17be
fix: dangling opline in ZEND_INIT_ARRAY (#18578)
This causes problems if an allocation profiler decides to walk the
stack, or if the engine itself OOMs on this opcode, and it tries to
print file and line information.
2025-05-19 09:45:28 -06:00
David Carlier
88d6e7c238
fix regex typo for GH-18577 new test 2025-05-17 12:44:57 +01:00
David Carlier
4dcbd24bad
GH-18572: infinite stack recursion in fallback object comparison.
With nested objects and recursive comparisons, it is for now unavoidable
to have a stack overflow we do some early damage control attempt early
on with zend.max_allowed_stack_size check but ultimately more a band-aid
than a definitive solution.

close GH-18577
2025-05-17 11:20:16 +01:00
Eric Mann
2852177f4d
PHP-8.3 is now for PHP 8.3.22-dev 2025-04-22 06:09:24 -07:00
Jakub Zelenka
b57f425cfe
PHP 8.3 is now for PHP 8.3.21-dev 2025-03-25 22:09:16 +01:00
Niels Dossche
2ec8d37eb4
Fix GH-18107: Opcache CFG jmp optimization with try-finally breaks the exception table
If there's a try-finally where the try_op starts on a basic block with a
single JMP, and the JMP optimization causes that basic block to become
unreachable, then we update try_op.
In this case, there is no catch_op, so try_op is erroneously set to 0,
we should instead set it to `b->start`.

Closes GH-18110.
2025-03-21 13:56:31 +01:00
Daniel Scherzer
fa3c1c81d5
Fix GH-17836: zend_vm_gen.php shouldn't break on Windows line endings
Closes GH-18121.
2025-03-21 11:50:34 +01:00
Niels Dossche
447d143b9d
Fixed bug GH-13193 again
Closes GH-13193.
2025-03-21 11:47:52 +01:00
Arnaud Le Blanc
1c182674b0
Destroy temporary module classes in reverse order
We destroy classes of dl()'ed modules in clean_module_classes(), during
shutdown. Child classes of a module use structures of the parent class (such as
inherited properties), which are destroyed earlier, so we have a use-after-free
when destroying a child class.

Here I destroy classes in reverse order, as it is done in zend_shutdown() for
persistent classes.

Fixes GH-17961
Fixes GH-15367
2025-03-14 10:45:17 +01:00
Eric Mann
517d7d909d
PHP-8.3 is now for PHP-8.3.20-dev 2025-03-12 06:34:55 -07:00
Ilija Tovilo
ef2c459941
Use-after-free for ??= due to incorrect live-range calculation
Fixes GHSA-rwp7-7vc6-8477
2025-03-11 22:10:21 +01:00
Niels Dossche
ce8ab5f16a
Fix GH-17736: Assertion failure zend_reference_destroy()
The cache slot for FETCH_OBJ_W in function `test` is primed with the
class for C. The next call uses a simplexml instance and reuses the same
cache slot. simplexml's get_property_ptr handler does not use the cache
slot, so the old values remain in the cache slot. When
`zend_handle_fetch_obj_flags` is called this is not guarded by a check
for the class entry. So we end up using the prop_info from the property
C::$a instead of the simplexml property.

This patch adds a reset to the cache slots in the property address fetch
code and also in the extensions with a non-standard reference handler.
This keeps the run time cache consistent and avoids the issue without
complicating the fast paths.

Closes GH-17739.
2025-03-02 22:33:32 +01:00
Eric Mann
00a772bf94
PHP-8.3 is now for PHP 8.3.19-dev 2025-02-25 09:20:39 -08:00
Tim Düsterhus
00d4390ea1
Free the trampoline when deprecation on materializing __callStatic() of trait throws (#17729)
Fixes php/php-src#17728
2025-02-07 10:53:14 +01:00
Tim Düsterhus
0607b663d3
Disallow calls to abstract __call() / __callStatic() (#17719)
Fixes php/php-src#17718
2025-02-07 09:36:33 +01:00
Niels Dossche
7e06a81bbd
Fix fallback paths in fast_long_{add,sub}_function
This was asked to be checked in https://github.com/php/php-src/pull/17472#issuecomment-2591325036

There are 2 issues:
1) The UB in the if can overflow, and can be fixed by using zend_ulong
   for the sum/sub.
2) fast_long_sub_function() has a problem when result aliases.
   This is fixed in the same way as fast_long_add_function() works.

Closes GH-17666.
2025-02-03 22:38:00 +01:00
Tim Düsterhus
f8b57ff1bf
zend_execute: Suppress values in UnhandledMatchError for zend.exception_ignore_args=1 (#17619)
Fixes php/php-src#17618.
2025-01-31 10:19:49 +01:00
Ilija Tovilo
333f5dd848
Fix stack overflow detection for variable compilation
Closes GH-17623
2025-01-29 23:27:27 +01:00
Jakub Zelenka
c4b678fa70
PHP-8.3 is now for PHP 8.3.18-dev 2025-01-28 19:45:52 +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
Niels Dossche
5344bcca97
Fix GH-17408: Assertion failure Zend/zend_exceptions.c
`zend_test_create_throwing_resource` sets the exception in the `test`
call frame and unwinds to `main`. It then throws for the `resource`
variable and verifies that the exception opline is set. However, it
wasn't set in `main`, it was set at the `test` call frame and rethrown later.
The assertion is too conservative, but the end result is right, so drop
the assertion.

Closes GH-17533.

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2025-01-21 08:20:38 +01:00
Ilija Tovilo
a6a290d541
Relax final+private warning for trait methods with inherited final
Fixes GH-17214
Closes GH-17381
2025-01-13 16:46:01 +01:00
Niels Dossche
a2b8204880
Add comment
Closes GH-17274.
2025-01-09 19:52:13 +01:00
Niels Dossche
7626e88de7
Fix GH-16892: ini_parse_quantity() fails to parse inputs starting with 0x0b 2025-01-09 19:51:18 +01:00
Niels Dossche
2c267722b3
Fix GH-16886: ini_parse_quantity() fails to emit warning for 0x+0 2025-01-09 19:51:17 +01:00
Niels Dossche
e6e2ec56ab
Merge duplicate code blocks
This makes the code less error-prone.
2025-01-09 19:51:17 +01:00
Eric Mann
717b75cb43
PHP-8.3 is now for PHP-8.3.17-dev 2024-12-31 08:46:21 -08:00
Niels Dossche
2c3b56ded0
Fix GH-17216: Trampoline crash on error
The error handling is incomplete on argument cleanup.
1. The fci is not cleared which means that zend_free_trampoline() is
   never called.
2. The cleaning for extra named arguments was missing, resulting in
   memory leak.

Closes GH-17219.
2024-12-21 00:25:06 +01:00
Arnaud Le Blanc
9e7932b292
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Add observer temporary to dl'ed functions
2024-12-20 18:46:55 +01:00
Arnaud Le Blanc
6f579934f0
Add observer temporary to dl'ed functions
When observer is enabled, we normally add an extra temporary to all
functions, to store the previously observed frame. However, this is done in
zend_observer_post_startup() so it doesn't happen to dl'ed() functions.

One possible fix would be to move that from zend_observer_post_startup()
to zend_register_functions(), but this would be too early: Observer may
not be enabled when zend_register_functions() is called, and may still be
enabled later.

However, when zend_register_functions() is called at run-time (during dl()),
we know definitively whether observer is enabled.

Here I update zend_register_functions() to add a temporary to dl'ed()
functions when observer is enabled.

Fixes: GH-17211
Closes: GH-17220
2024-12-20 18:45:34 +01:00
Niels Dossche
160a4a65ad
Export visibility for promoted property (8.3) 2024-12-17 19:14:07 +01:00
Niels Dossche
ee0daa59db
Fix GH-17162: zend_array_try_init() with dtor can cause engine UAF
Closes GH-17167.
2024-12-15 20:11:40 +01:00
Ilija Tovilo
cdfd960150
Fix ZEND_MATCH_ERROR misoptimization
op1 of ZEND_MATCH_ERROR, which refers to the match expression, is not freed by
MATCH_ERROR itself. Instead, it is freed by ZEND_HANDLE_EXCEPTION. For normal
control flow, a FREE is placed at the end of the match expression.

Since FREE may appear after MATCH_ERROR in the opcode sequence, we need to
correctly handle op1 of MATCH_ERROR as alive.

Fixes GH-17106
Closes GH-17108
2024-12-12 13:10:34 +01:00
Jakub Zelenka
b1e3dcf88a
PHP-8.3 is now for PHP 8.3.16-dev 2024-12-03 18:45:43 +01:00
Sergey Panteleev
7fbeee0c2f
PHP-8.2 is now for PHP 8.2.28-dev 2024-12-03 16:48:02 +03: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
Niels Dossche
02b1056714
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix is_zend_ptr() huge block comparison
2024-11-26 19:24:31 +01:00
Niels Dossche
18674e39ad
Fix is_zend_ptr() huge block comparison
We should compare the block memory, not the block metadata (See
zend_mm_add_huge_block).
This caused random test failure for ext/ffi/tests/gh14626.phpt when the
malloc() performed by the FFI code lies close to the block metadata, and
the size of the block is large enough.

This was reported by https://github.com/php/php-src/issues/16902#issuecomment-2498310452

Closes GH-16938.
2024-11-26 19:24:05 +01:00
Niels Dossche
6a632a2d60
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16630: UAF in lexer with encoding translation and heredocs
2024-11-18 19:59:01 +01:00
Niels Dossche
fc1db70f10
Fix GH-16630: UAF in lexer with encoding translation and heredocs
zend_save_lexical_state() can be nested multiple times, for example for
the parser initialization and then in the heredoc lexing. The input
should not be freed if we restore to the same filtered string.

Closes GH-16716.
2024-11-18 19:58:02 +01:00
Niels Dossche
ed59c00661
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16799: Assertion failure at Zend/zend_vm_execute.h:7469
2024-11-15 20:03:19 +01:00