Commit graph

18326 commits

Author SHA1 Message Date
Shivam Mathur
ea6a7a9725
Fix CI for windows-2022
This is a continuation of GH-18927 to fix CI for windows-2022
2025-06-25 03:17:32 +05:30
Shivam Mathur
91f2458020
Merge branch 'PHP-8.1' into PHP-8.2 2025-06-25 02:00:11 +05:30
Shivam Mathur
6233dc6210
Switch to windows-2022 in CI (#18927)
* Switch to windows-2022 in CI

windows-2019 runner will be dropped by GitHub on 2025-06-30.

* xfail test cases that fail on windows-2022
2025-06-25 01:57:07 +05:30
Ilija Tovilo
7841c8a3df
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Track heap->real_size for USE_TRACKED_ALLOC
2025-06-20 14:49:47 +02:00
Ilija Tovilo
9cacc57350
Track heap->real_size for USE_TRACKED_ALLOC
real_size is returned by memory_get_usage(true), which previously returned 0.
Discovered in Symfony ConsumeMessagesCommandTest::testRunWithMemoryLimit()
through nightly.

Closes GH-18880
2025-06-20 14:48:47 +02:00
Pierrick Charron
b617b0832c
PHP-8.2 is now for PHP 8.2.29-dev 2025-03-11 18:31:23 -04:00
Ben Ramsey
858c378930
PHP-8.1 is now for PHP 8.1.33-dev 2025-03-11 16:34:23 -05:00
Ilija Tovilo
1009ff65cc
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Upgrade security branches to Ubuntu 22.04
2025-03-06 15:24:35 +01:00
Ilija Tovilo
5fcc8d4cd1
Upgrade security branches to Ubuntu 22.04
20.04 goes out of security support in 2 months. Backporting various
commits.

See d98963a071
See af721c9c36
See 378b79b90c

Closes GH-17963
2025-03-06 15:24:15 +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
806d2e073c
Backport GH-16348
Agreed by RM: https://github.com/php/php-src/issues/16168#issuecomment-2525433557

The inline assembly uses labels with the prefix `.L`. On Linux systems
this is the local label prefix. It appears that macOS uses `L` as a
local prefix, which means that the prefix used in the inline assembly is not
local for macOS systems [1].
When combined with inlining, this causes the compiler to get confused
and merge a part of the inline assembly between different functions,
causing control flow to jump from one function to another function.
This is avoided on PHP 8.2 and up by the fact that it
uses `zend_never_inline NOIPA`, but nothing guarantees that compiler
changes won't affect this as well.

To solve this issue, we instead use local labels. These will make the
compiler pick the correct prefix, preventing the issue.

Additionally, while here, we also change the computation of `delta`.
It is undefined behaviour to compute the pointer difference between
two different objects. To circumvent this, we cast first to `uintptr_t`.

This change is cleanly backportable to 8.1 for vendors to pick up.

[1] https://github.com/php/php-src/issues/16168#issuecomment-2404792553

With the help of investigation and testing of @ryandesign.

Closes GH-16348.
2024-12-09 21:00:05 +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
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
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
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
553d79c709
Fix GH-16799: Assertion failure at Zend/zend_vm_execute.h:7469
zend_is_callable_ex() can unfortunately emit a deprecation, and then
a user error handler can throw an exception. This causes an assert
failure at ZEND_VM_NEXT_OPCODE(). We fix this by checking if there's an
exception after zend_is_callable_ex().

Closes GH-16803.
2024-11-15 20:02:26 +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
David Carlier
875a9dc4c4
Fix introduced leaks from GH-15715.
Choosing here to shrink the requested allocation to its max value.
2024-11-08 12:27:03 +00:00
David Carlier
e74e66e3f7
Fix oss-fuzz report triggered by GH-15712 commit.
It triggered allocation overflow which, even fixed, in turn gives memory
leak on 32 bits but the allocator relies on signed integers.

close GH-15915
2024-11-07 22:51:05 +00:00
Pierrick Charron
f5895792e7
PHP-8.2 is now for PHP 8.2.27-dev 2024-11-05 12:47:25 -05:00
Ilija Tovilo
4b9e59b430
[skip ci] Use bool for zend_array_sort()
zend_bool is removed in higher branches.
2024-11-04 15:59:18 +01:00
Ilija Tovilo
2bdce61390
Fix array going away during sorting
Fixes GH-16648
Closes GH-16654
2024-11-04 15:50:35 +01:00
Christoph M. Becker
ec68d3c608
Properly initialize _override executor globals
These have been introduced a while ago[1], but their initialization has
been overlooked.  Since we cannot rely on TLS variables to be zeroed,
we catch up on this.

[1] <e3ef7bbbb8>

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>

Closes GH-16658.
2024-10-31 23:38:01 +01:00
Ilija Tovilo
25c0993902
Backport CI fixes to security branches
Closes GH-16469

Working towards GH-16286

commit e0db221143b808d97bc3a44e9f0968c6308794b4
Author: Ilija Tovilo <ilija.tovilo@me.com>
Date:   Fri Oct 25 22:48:20 2024 +0200

    Move CFLAGS into ./configure command for consistency

commit 8ad67768250d181cd7fef30e0c866625bbd8ac94
Author: Ilija Tovilo <ilija.tovilo@me.com>
Date:   Fri Oct 25 22:47:03 2024 +0200

    Also upgrade nightly to macOS 13

commit 58a88ccb9f
Author: Ilija Tovilo <ilija.tovilo@me.com>
Date:   Wed Oct 23 19:07:59 2024 +0200

    Fix call to dc[n]gettext in tests with 0 $category

    This causes a segfault on PHP-8.1

commit 611af05c50
Author: Ilija Tovilo <ilija.tovilo@me.com>
Date:   Fri Dec 8 13:36:52 2023 +0100

    [skip ci] Skip intermittently failing curl test on macOS

    The test fails with "CURL ERROR: 56". I will create an issue for it shortly.

commit ec745178bb
Author: Ilija Tovilo <ilija.tovilo@me.com>
Date:   Wed Oct 23 19:05:32 2024 +0200

    Backport parts of 9999a0c for gettext

    See 9999a0cb75

commit 5ce703496f
Author: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Date:   Sun Jul 28 14:34:26 2024 +0200

    Fix CI failure on macOS after Curl update

commit 714a3e7071
Author: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Date:   Sat Jul 27 16:09:50 2024 +0200

    Fix CI failure after Curl update (#15124)

commit 4f2eb921b9
Author: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Date:   Thu May 23 22:20:37 2024 +0200

    Fix GH-14307: Test curl_basic_024 fails with curl 8.8.0

    Curl changed the behaviour, from the changelog:
      - lib: make protocol handlers store scheme name lowercase curl/curl@c294f9c

    From the docs: "The returned scheme might be upper or lowercase. Do
    comparisons case insensitively."

    Closes GH-14312.

commit 251195b41b
Author: Ayesh Karunaratne <ayesh@aye.sh>
Date:   Thu Feb 1 02:03:55 2024 +0700

    ext/curl: Fix failing tests due to string changes in libcurl 8.6.0

    Upstream libcurl 8.6.0 contains a change[^1] that caused a test failure.
    This fixes it by updating the test's `EXPECTF` to use a regex to account for both string patterns.

    [^1]: 45cf4755e7 (diff-a8a54563608f8155973318f4ddb61d7328dab512b8ff2b5cc48cc76979d4204cL1683)

    Closes GH-13293.

commit fc5d83f2b1
Author: Christoph M. Becker <cmbecker69@gmx.de>
Date:   Wed Oct 16 22:46:20 2024 +0200

    Prepare for necessary move to macOS 13

    GH will remove macOS 12 runner images as of December 3rd, so we prepare
    for that.

    Besides the obvious need to change the runner, we also suppress a
    couple of warnings, because otherwise the build would fail due to
    `-Werror`.
2024-10-28 15:57:16 +01:00
Ilija Tovilo
2d068c4f47
Fix lineno for inheritance errors of early bound classes
Fixes GH-16508
Closes GH-16532
2024-10-22 15:16:43 +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
8720063c4e
Fix propagation of ZEND_ACC_RETURN_REFERENCE for call trampoline
Fixes GH-16515
Closes GH-16529
2024-10-22 14:47:01 +02:00
Dmitry Stogov
fe513655dc
Fix GH-16499: [JIT] Undefined to null coercion issues for return 2024-10-21 14:50:50 +03:00
Arnaud Le Blanc
1d94fb86b7
Fix handling of invalid iterator in zend_weakmap_iterator_get_current_key()
Fixes GH-16371
Closes GH-16436
2024-10-15 12:22:35 +02:00
Ilija Tovilo
b5c09b1a61
Fix exception in assert() callback with bail enabled
Fixes GH-16293
Closes GH-16304
2024-10-14 13:59:26 +02:00
Niels Dossche
e2e2b3ab62
Fix GH-16168: php 8.1 and earlier crash immediately when compiled with Xcode 16 clang on macOS 15
The inline assembly uses labels with the prefix `.L`. On Linux systems
this is the local label prefix. It appears that macOS uses `L` as a
local prefix, which means that the prefix used in the inline assembly is not
local for macOS systems [1].
When combined with inlining, this causes the compiler to get confused
and merge a part of the inline assembly between different functions,
causing control flow to jump from one function to another function.
This is avoided on PHP 8.2 and up by the fact that it
uses `zend_never_inline NOIPA`, but nothing guarantees that compiler
changes won't affect this as well.

To solve this issue, we instead use local labels. These will make the
compiler pick the correct prefix, preventing the issue.

Additionally, while here, we also change the computation of `delta`.
It is undefined behaviour to compute the pointer difference between
two different objects. To circumvent this, we cast first to `uintptr_t`.

This change is cleanly backportable to 8.1 for vendors to pick up.

[1] https://github.com/php/php-src/issues/16168#issuecomment-2404792553

With the help of investigation and testing of @ryandesign.

Closes GH-16348.
2024-10-11 09:09:05 +02:00
Sergey Panteleev
5f5824015c
PHP-8.2 is now for PHP 8.2.26-dev 2024-10-08 19:53:22 +05: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
Arnaud Le Blanc
c2115a43e3
Handle references properties of the Exception class
Fixes GH-16188
Closes GH-16196
2024-10-07 15:03:31 +02:00
Arnaud Le Blanc
6e55f4df23
Fix assertion failure in generator dtor (#16025) 2024-10-02 12:29:19 +02:00
Ilija Tovilo
706bcdbc1a
Fix printing backtrace of fake generator frame
Fixes GH-15851
Closes GH-15952
2024-09-27 17:34:51 +02:00
Ilija Tovilo
15a0c3a9d4
Fix failed assertion when promoting Serialize deprecation to exception
Fixes GH-15907
Closes GH-15951
2024-09-26 22:01:59 +02:00
Ben Ramsey
fcbcf2f281
PHP-8.1 is now for PHP 8.1.31-dev 2024-09-26 12:52:41 -05:00
David Carlier
5feb29ea03
Fix ubsan build on freebsd regarding float.
due to the system header machine/ieeefp.h proceeding to a bitshift
operation.

close GH-15935
2024-09-25 00:39:08 +01:00
David Carlier
503d9145e0
Fix GH-15712: overflow on float print with precision ini large value.
When allocating enough room for floats, the allocator used overflows with
large ndigits/EG(precision) value which used an signed integer to
increase the size of thebuffer.
Testing with the zend operator directly is enough to trigger
the issue rather than higher level math interface.

close GH-15715
2024-09-11 21:19:07 +01:00
Pierrick Charron
7e722e3ba4
PHP-8.2 is now for PHP 8.2.25-dev 2024-09-10 15:26:28 -04:00
Niels Dossche
86ef8d5466
Fix GH-15661: Access null pointer in Zend/Optimizer/zend_inference.c
Closes GH-15666.
2024-09-09 20:10:16 +02:00
Ilija Tovilo
1f35e2a999
Fix uninitialized CG(zend_lineno)
Closes GH-15813
2024-09-09 19:34:05 +02:00
Ilija Tovilo
b9fdc0bdcd
Fix uninitialized EG(user_error_handler_error_reporting)
Closes GH-15812
2024-09-09 19:33:32 +02:00
Ilija Tovilo
99504aa148
Intercept strlcpy and strlcat for msan on Clang 17 (#12674) 2024-09-09 16:45:46 +02:00
Ilija Tovilo
08e0729c57
Fix uninitialized lineno in constant AST of internal enums
Closes GH-15806
2024-09-08 23:44:11 +02:00
Arnaud Le Blanc
cd25500766
Do not scan generator frames more than once (#15330) 2024-08-28 17:43:17 +02:00
Go Kudo
836e6fa900
zend_max_execution_timer: fix gcc compatibility (#15447) 2024-08-17 05:20:04 +09:00
Go Kudo
ec9cdcd2bc
Fix MSan false-positive in zend_max_execution_timer (#15408)
Explicitly mark memory regions as unpoisoned for zend_max_execution_timer on ZTS, as MemorySanitizer in clang >= 18 causes false positives.
2024-08-17 02:54:03 +09:00
Sergey Panteleev
84d8fa9f53
PHP-8.2 is now for PHP 8.2.24-dev 2024-08-13 17:18:16 +03:00