Commit graph

460 commits

Author SHA1 Message Date
Niels Dossche
4c751ec04c
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17938: UAF with zend_test opline observer and magic_quotes_gpc=1 (#17958)
2025-03-03 08:22:49 +01:00
Niels Dossche
504056888c
Fix GH-17938: UAF with zend_test opline observer and magic_quotes_gpc=1 (#17958) 2025-03-03 08:20:48 +01:00
David Carlier
96340e9eed
Merge branch 'PHP-8.3' into PHP-8.4 2025-02-23 13:23:38 +00:00
David Carlier
2c251f945c
[skip ci] zend_test adding closing tags to newer tests 2025-02-23 13:23:26 +00:00
David Carlier
e8dda54dd5
Merge branch 'PHP-8.3' into PHP-8.4 2025-02-23 10:45:46 +00:00
David Carlier
cefdf00e7e
Fix GH-17899: zend_test_compile_string crash on invalid script path.
when opcache is enabled.

close GH-17901
2025-02-23 10:45:10 +00:00
David Carlier
eabbb1c1c6
Merge branch 'PHP-8.3' into PHP-8.4 2025-02-15 10:12:20 +00:00
David Carlier
0f63bee3e9
Fix GH-17797: zend_test_compile_string crash on invalid script path.
When looking for the last slash of the script path, it leads to
underflow being promoted to SIZE_MAX being way beyond MAXPATHLEN.

close GH-17801
2025-02-15 10:11:27 +00:00
Niels Dossche
25543b4566
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17408: Assertion failure Zend/zend_exceptions.c
2025-01-21 08:21:13 +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
Niels Dossche
250e0ffe90
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16013 and bug #80857: Big endian issues
2024-12-25 21:33:43 +01:00
Niels Dossche
99a14b805e
Fix GH-16013 and bug #80857: Big endian issues
The FFI call return values follow widening rules.
We must widen to `ffi_arg` in the case we're handling a return value for types shorter than the machine width.
From http://www.chiark.greenend.org.uk/doc/libffi-dev/html/The-Closure-API.html:
> In most cases, ret points to an object of exactly the size of the type specified when cif was constructed.
> However, integral types narrower than the system register size are widened.
> In these cases your program may assume that ret points to an ffi_arg object.

If we don't do this, we get wrong values when reading the return values.

Closes GH-17255.

Co-authored-by: Dmitry Stogov <dmitry@zend.com>
2024-12-25 21:33:14 +01:00
Niels Dossche
ec9a606e5d
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix test expectation for PHP 8.3+
2024-11-25 20:33:20 +01:00
Niels Dossche
ff95138e38
Fix test expectation for PHP 8.3+ 2024-11-25 20:33:14 +01:00
Niels Dossche
43a3bd0608
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16908: _ZendTestMagicCallForward does not handle references well
2024-11-25 19:39:01 +01:00
Niels Dossche
d9fada4a71
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16908: _ZendTestMagicCallForward does not handle references well
2024-11-25 19:38:50 +01:00
Niels Dossche
99f5653ebb
Fix GH-16908: _ZendTestMagicCallForward does not handle references well
This testing code was never meant to be used this way, but fixing this
will at least stop fuzzers from complaining about this, so might still
be worthwhile.

Closes GH-16919.
2024-11-25 19:38:33 +01:00
Arnaud Le Blanc
8d30ed4f80
Fix compiler warning in zend_test
Closes GH-16650
2024-11-05 16:51:43 +01:00
Niels Dossche
bfd9e0cca3
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16628: FPM logs are getting corrupted with this log statement
  Fix GH-16601: Memory leak in Reflection constructors
2024-11-02 19:38:54 +01:00
Niels Dossche
16cda10650
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16628: FPM logs are getting corrupted with this log statement
  Fix GH-16601: Memory leak in Reflection constructors
2024-11-02 19:37:28 +01:00
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
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
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
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
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
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