Commit graph

496 commits

Author SHA1 Message Date
Niels Dossche
e643129bbb
Fix GH-16628: FPM logs are getting corrupted with this log statement
zlog_buf_prefix() can return a larger length than what actually was
written due to its use of snprintf(). The code in
zlog_stream_prefix_ex() does not take this into account, other callers
do. What ends up happening then is that stream->length is set to the
length as if snprintf() was able to write all bytes, causing
stream->length to become larger than stream->buf.size, causing a
segfault.

In case the buffer was too small we try with a larger buffer up to a
limit of zlog_limit. This makes sure that the stream length will remain
bounded by the buffer size.

This also adds assertions to make the programmer intent clear and catch
this more easily in debug builds.

Closes GH-16680.
2024-11-02 19:36:20 +01:00
Christoph M. Becker
836a162089
Don't fiddle with NDEBUG in C code (GH-16511)
* Don't fiddle with NDEBUG in C code

It is way to late to do this in php.h, since assert.h has already been
included.  Even pushing that down to zend_portability.h may not have
the desired effect.  Instead we define or undefine NDEBUG as CFLAG, so
that it works in all circumstances.

As a last resort we fail at build time, if `NDEBUG` is defined when
`ZEND_DEBUG` is enabled.

We also remove the useless workaround in zend_test to include assert.h
again, since that usually won't have any effect anyway.

Co-authored-by: Arnaud Le Blanc <arnaud.lb@gmail.com>
2024-10-27 18:20:59 +01:00
Ilija Tovilo
e05b56fdb1
Merge branch 'PHP-8.4'
* PHP-8.4:
  [skip ci] Fix overwritten observer ini setting for gh16514.phpt
2024-10-22 15:21:31 +02:00
Ilija Tovilo
0c297bab21
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  [skip ci] Fix overwritten observer ini setting for gh16514.phpt
2024-10-22 15:21:26 +02:00
Ilija Tovilo
a6bf2f591a
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [skip ci] Fix overwritten observer ini setting for gh16514.phpt
2024-10-22 15:21:20 +02:00
Ilija Tovilo
c5c4c3be44
[skip ci] Fix overwritten observer ini setting for gh16514.phpt 2024-10-22 15:20:56 +02:00
Ilija Tovilo
178ee5b879
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix handling of nested generator in zend_test observer
2024-10-22 14:52:19 +02:00
Ilija Tovilo
289f59ad48
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix handling of nested generator in zend_test observer
2024-10-22 14:52:07 +02:00
Ilija Tovilo
ce99adeb54
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix handling of nested generator in zend_test observer
2024-10-22 14:51:58 +02:00
Ilija Tovilo
69bcbdc3c5
Fix handling of nested generator in zend_test observer
This is the counterpart of GH-15952.

Fixes GH-16514
Closes GH-16530
2024-10-22 14:51:36 +02:00
Christoph M. Becker
50acf5eb15
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-16266: _ZendTestClass::test() segfaults on named parameter
2024-10-21 19:46:34 +02:00
Christoph M. Becker
241e3e0e27
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16266: _ZendTestClass::test() segfaults on named parameter
2024-10-21 19:46:02 +02:00
Christoph M. Becker
713c71adbd
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16266: _ZendTestClass::test() segfaults on named parameter
2024-10-21 19:44:34 +02:00
Christoph M. Becker
b73bcaa47c
Fix GH-16266: _ZendTestClass::test() segfaults on named parameter
We need to assign the proper number of arguments.

Closes GH-16271.
2024-10-21 19:43:33 +02:00
Christoph M. Becker
01aeaf2e95
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-16414: zend_test.observer.observe_function_names may segfault
2024-10-20 12:11:42 +02:00
Christoph M. Becker
909cecb7fa
Fix GH-16414: zend_test.observer.observe_function_names may segfault
Unless `zend_test.observer.enabled` is on, we must not add observer
handlers, so we let the INI modify handler fail early.

We also need to ensure that the functions to observe have already been
called, so that their begin and end handlers are properly initialized.
Otherwise we will not observe the function execution, but a segfault.

Co-authored-by: Bob Weinand <bobwei9@hotmail.com>

Closes GH-16438.
2024-10-20 12:11:08 +02:00
Tim Düsterhus
3401d55726
zend_weakrefs: Add zend_weakrefs_hash_(clean|destroy)() (#16439)
These are equivalent to `zend_hash_clean()` and `zend_hash_destroy()`
respectively, but take care of correctly unregistering the weak references to
the keys.

This addition rounds off the weakmap functionality added in
471102edcd by taking one possible footgun away
from the user.
2024-10-14 18:57:08 +02:00
Ilija Tovilo
253f4af90e
[skip ci] Fix new closure dump syntax in test 2024-10-14 15:03:53 +02:00
Ilija Tovilo
e7dc0d2c40
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix segfault on debug_backtrace() in _ZendTestFiber
2024-10-14 14:05:21 +02:00
Ilija Tovilo
94bd6ca080
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix segfault on debug_backtrace() in _ZendTestFiber
2024-10-14 14:05:13 +02:00
Ilija Tovilo
5955ce8987
Fix segfault on debug_backtrace() in _ZendTestFiber
Fixes GH-16230
Closes GH-16299
2024-10-14 14:04:49 +02:00
Ilija Tovilo
7d99355dad
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix segfault in zend_test_execute_internal()
2024-10-14 14:03:09 +02:00
Ilija Tovilo
0237361679
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix segfault in zend_test_execute_internal()
2024-10-14 14:03:01 +02:00
Ilija Tovilo
5c798415cd
Fix segfault in zend_test_execute_internal()
zend_pass_function also has no name, so we might also be referring to an
internal function here. In this case, ZEND_NEW uses the zend_pass_function when
there is no constructor.

Fixes GH-16294
Closes GH-16301
2024-10-14 14:02:36 +02:00
Christoph M. Becker
8a5c716eb8
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16388: UB when freeing a cloned _ZendTestFiber
2024-10-12 22:49:45 +02:00
Christoph M. Becker
41d75f42ec
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16388: UB when freeing a cloned _ZendTestFiber
2024-10-12 22:48:46 +02:00
Christoph M. Becker
a3eb1fd86d
Fix GH-16388: UB when freeing a cloned _ZendTestFiber
Since there is no need to clone instances of this test class, we
prevent cloning in the first place.

Closes GH-16400.
2024-10-12 22:48:11 +02:00
Niels Dossche
b24cc7386b
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fixed GH-16233: Observer segfault when calling user function in internal function via trampoline
2024-10-07 17:18:32 +02:00
Niels Dossche
0338008852
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fixed GH-16233: Observer segfault when calling user function in internal function via trampoline
2024-10-07 17:17:27 +02:00
Niels Dossche
e715dd0afb
Fixed GH-16233: Observer segfault when calling user function in internal function via trampoline
In the test, I have an internal `__call` function for `_ZendTestMagicCallForward` that calls the global function with name `$name` via `call_user_function`.
Note that observer writes the pointer to the previously observed frame in the last temporary of the new call frame (`*prev_observed_frame`).

The following happens:
First, we call `$test->callee`, this will be handled via a trampoline with T=2 for the two arguments. The call frame is allocated at this point. This call frame is not observed because it has `ZEND_ACC_CALL_VIA_TRAMPOLINE` set. Next we use `ZEND_CALL_TRAMPOLINE` to call the trampoline, this reuses the stack frame allocated earlier with T=2, but this time it is observed. The pointer to the previous frame is written outside of the call frame because `T` is too small (should be 3). We are now in the internal function `_ZendTestMagicCallForward::__call` where we call the global function `callee`. This will push a new call frame which will overlap `*prev_observed_frame`. This value gets overwritten by `zend_init_func_execute_data` when `EX(opline)` is set because `*prev_observed_frame` overlaps with `EX(opline)`. From now on, `*prev_observed_frame` is corrupted. When `zend_observer_fcall_end` is called this will result in reading wrong value `*prev_observed_frame` into `current_observed_frame`. This causes issues in `zend_observer_fcall_end_all` leading to the segfault we observe.

Despite function with `ZEND_ACC_CALL_VIA_TRAMPOLINE` not being observed, the reuse of call frames makes problems when `T` is not large enough.
To fix this, we make sure to add 1 to `T` if `ZEND_OBSERVER_ENABLED` is true.

Closes GH-16252.
2024-10-07 17:16:43 +02:00
Niels Dossche
589da5b008
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Add SKIPIF for ZendMM for observer_fiber_functions_03.phpt
2024-10-06 18:00:49 +02:00
Niels Dossche
bd8495ef93
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Add SKIPIF for ZendMM for observer_fiber_functions_03.phpt
2024-10-06 18:00:43 +02:00
Niels Dossche
fbb1001d84
Add SKIPIF for ZendMM for observer_fiber_functions_03.phpt
This test uses memory_limit, so it fails when using USE_ZEND_ALLOC=0.
2024-10-06 18:00:33 +02:00
Niels Dossche
9f0138babe
Merge branch 'PHP-8.3'
* PHP-8.3:
  Update test for changed error message format in libxml 2.13
2024-09-12 23:11:28 +02:00
Niels Dossche
6f975a271f
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Update test for changed error message format in libxml 2.13
2024-09-12 23:11:23 +02:00
Niels Dossche
3354cc6e89
Update test for changed error message format in libxml 2.13 2024-09-12 23:11:14 +02:00
DanielEScherzer
5dd0575698
Generated arginfo header files: combine preprocessor conditional blocks (#15736)
When functions' or class methods' availability is based on some preprocessor
condition, the generated arginfo header files wrap the declarations in the
preprocessor `#if` conditional blocks, one per declaration, even if they are in
the same conditional block based on comments in the stub file. Instead of
having multiple conditional blocks one after the other with the same condition,
combine them into a single conditional block.
2024-09-04 13:04:22 +02:00
DanielEScherzer
53cb89670c
Generated arginfo header files: remove empty zend_function_entry arrays (#15705)
When a class (or enum) has no methods, rather than using an array that only
contains `ZEND_FE_END`, use `NULL` for the functions. The implementation of
class registration for internal classes, `do_register_internal_class()` in
zend_API.c, already skips classes where the functions are `NULL`. By removing
these unneeded arrays, we can reduce the size of the header files, while also
removing an unneeded call to zend_register_functions() for each internal class
with no extra methods.
2024-09-03 23:19:53 +02:00
Máté Kocsis
8d12f666ae
Fix registration of internal readonly child classes (#15459)
Currently, internal classes are registered with the following code:

INIT_CLASS_ENTRY(ce, "InternalClass", class_InternalClass_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ...;

This has worked well so far, except if InternalClass is readonly. It is because some inheritance checks are run by zend_register_internal_class_ex before ZEND_ACC_READONLY_CLASS is added to ce_flags.

The issue is fixed by adding a zend_register_internal_class_with_flags() zend API function that stubs can use from now on. This function makes sure to add the flags before running any checks. Since the new API is not available in lower PHP versions, gen_stub.php has to keep support for the existing API for PHP 8.3 and below.
2024-08-24 12:36:54 +02:00
Gina Peter Banyard
1e3d918936
ext/core: Deprecate passing E_USER_ERROR to trigger_error() (#15308)
RFC: https://wiki.php.net/rfc/deprecations_php_8_4#deprecate_passing_e_user_error_to_trigger_error
2024-08-09 15:51:07 +01:00
Ilija Tovilo
2e9cc9bc30
Allow optimizer to depend on preloaded symbols (#15021)
* Allow optimizer to depend on preloaded symbols

It is safe for the optimizer to rely on preloaded symbols. This can occur when
compiling non-preloaded files, referencing preloaded ones.

* Disable inline pass for observer test

* Move duplicated code into functions

* Add comment to specific optimization value

* Optimizer should only rely on preloaded symbols in the symbol table

* Fix skipif for windows
2024-08-02 17:35:27 +02:00
Peter Kokot
1ceadaed52
Autotools: Normalize and quote all PHP_NEW_EXTENSION arguments (#15144)
This adds Autoconf quote characters to all PHP_NEW_EXTENSION arguments
and syncs the CS across the php-src Autotools build system.
2024-07-29 00:14:59 +02:00
Niels Dossche
19813b5b7e
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-14741: Segmentation fault in Zend/zend_types.h
2024-07-09 00:57:35 +02:00
Niels Dossche
4c95cb37f5
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-14741: Segmentation fault in Zend/zend_types.h
2024-07-09 00:57:28 +02:00
Niels Dossche
eb8c3cb79a
Fix GH-14741: Segmentation fault in Zend/zend_types.h
The create_obj handler of InternalIterator is overwritten, but not the
clone_obj handler. This is not allowed.
In PHP 8.2 this didn't cause a segfault because the standard object
handler was used for the clone instead of the internal handler.
So then it allocates and frees the object using the standard object handlers.
In 8.3 however, the object is created using the standard object handler and
freed using the custom handler, resulting in the buffer overflow.
Even though bisect points to 1e1ea4f this only reveals the bug.

Closes GH-14882.
2024-07-09 00:56:53 +02:00
Benjamin Eberlei
72c874691b
RFC: Add #[\Deprecated] Attribute (#11293)
see https://wiki.php.net/rfc/deprecated_attribute

Co-authored-by: Tim Düsterhus <tim@tideways-gmbh.com>
Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2024-07-02 09:44:25 +02:00
Máté Kocsis
a2cecd2a6f
Remove ZEND_STATIC_ASSERT() calls from legacy arginfo files
After report in 5992a29724 (r143540472)
2024-06-27 21:52:27 +02:00
Arnaud Le Blanc
f7df238971
Merge branch 'PHP-8.3'
* PHP-8.3:
  [ci skip] NEWS for GH-14626
  [ci skip] NEWS for GH-14626
  Fix is_zend_ptr() for huge blocks (#14626)
2024-06-25 15:18:58 +02:00
Arnaud Le Blanc
bc57c77fa2
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [ci skip] NEWS for GH-14626
  Fix is_zend_ptr() for huge blocks (#14626)
2024-06-25 15:15:46 +02:00
Arnaud Le Blanc
1ff277dee2
Fix is_zend_ptr() for huge blocks (#14626)
is_zend_ptr() expected zend_mm_heap.huge_list to be circular, but it's in fact NULL-terminated. It could crash when at least one huge block exists and the ptr did not belong to any block.
2024-06-25 15:14:00 +02:00