1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

1324 Commits

Author SHA1 Message Date
Ilija Tovilo
80b1ede843 [skip ci] Fix uninitialized fn_flags2 for internal functions
This field is still unused on master, but required for GH-19941.
2026-03-13 20:26:31 +01:00
Tim Düsterhus
303104e2bf zend: Define C23 enum zend_class_type (#21241)
Checked for “binary and” comparisons using Coccinelle:

    @@
    struct _zend_class_entry *e;
    expression x;
    @@

    * (e->type & x)

    @@
    zend_class_entry *e;
    expression x;
    @@

    * (e->type & x)
2026-02-17 16:49:45 +01:00
Khaled Alam
32bd33983d Remove unreachable code after zend_error_noreturn calls (GH-20983) 2026-02-02 14:14:15 +01:00
Arshid
927b9eecb6 Drop unused error_type argument from zend_check_magic_method_public() (GH-21095) 2026-01-30 21:46:26 +01:00
Jorg Adam Sowa
9f774e3a85 chore: improve errror message when passing named parameter for variadic in unsupported internal functions (#21012) 2026-01-25 18:27:57 +00:00
Arnaud Le Blanc
626f3c3c7c Unify arg info representation for internal and user functions
The arg_info member of zend_function is now always a zend_arg_info*. Before,
it was a zend_internal_arg_info* on internal functions, unless the
ZEND_ACC_USER_ARG_INFO flag was set.

Closes GH-19022
2025-12-15 16:50:49 +01:00
Niels Dossche
50131de9f3 Zend: Use zend_hash_str_find_ptr_lc() in zend_get_module_version() 2025-12-10 11:13:39 -08:00
Niels Dossche
1ee8dfd6fc Remove pointless EG(exception) checks when parsing coercive string argument (#20568)
The is_numeric_str_function() family cannot throw.
2025-11-24 19:09:23 +01:00
Gina Peter Banyard
ccda8b16d4 zend_API.c: add const qualifiers 2025-11-07 21:10:52 +00:00
Gina Peter Banyard
fe74aa1a9a zend_API.c: rename variable to prevent variable shadowing 2025-11-07 21:10:52 +00:00
Gina Peter Banyard
55d449fca4 Zend: remove zend_set_hash_symbol() API (#20413)
This is unused both within php-src and a SourceGraph search returned 0 results.

This is also confusing as it talks about symbol tables without actually using any of the corresponding update functions.
2025-11-07 20:01:04 +00:00
Gina Peter Banyard
297179dbcc zend_object_handlers: add some const qualifiers (#20402) 2025-11-06 22:47:39 +00:00
Gina Peter Banyard
423e50c57d zend_object_handler.c: call zend_get_call_trampoline_func() and pass zend_function* directly (#20297)
Abstracting away the bool parameter is not that useful, and doesn't make the code more legible.
Moreover, it is not needed if one passes the zend_function* directly, which we always have.
This is because it can be derived/copied from the fn_flags.
2025-11-05 21:46:32 +00:00
Gina Peter Banyard
c669fbf370 Zend/zend_compile: add const qualifiers 2025-10-30 12:02:43 +00:00
Gina Peter Banyard
0df31e5a5b Merge branch 'PHP-8.5'
* PHP-8.5:
  Update NEWS for null deprecation bug fix
  Fix GH-20194: null offset deprecation not emitted for writes (#20238)
2025-10-29 18:37:29 +00:00
Gina Peter Banyard
9a1b8a785d Fix GH-20194: null offset deprecation not emitted for writes (#20238)
Based on a patch from @ndossche
2025-10-29 18:36:10 +00:00
Gina Peter Banyard
7815ab9b22 Zend: add const qualifiers when possible for _zend_execute_data.func related uses (#20263)
The initial motivation was to see if it is possible to make the `func` field of `_zend_execute_data` constant.

For various reasons, this is not possible, but the added `const` qualifiers during this exploration remain useful.
2025-10-29 13:22:56 +00:00
Gina Peter Banyard
c0214e49d2 Zend: remove zend_make_callable() function (#20269)
The name of this function is confusing, it doesn't make a zval callable just normalizes strings to an array pair if the string references a static method.
In general, to store a userland function it is encouraged to store the resolved FCC rather than the zval.

Moreover, a sourcegraph search shows no usage of this API in external open source code.
2025-10-26 18:28:40 +00:00
Gina Peter Banyard
275ec6f335 Zend: make zend_copy_parameters_array() private (#20265)
And slightly refactor implementation.
2025-10-25 22:36:09 +01:00
Gina Peter Banyard
ba4a12bc39 Zend: add const qualifier for scope in read property functions (#19949) 2025-09-24 18:53:50 +01:00
Tim Düsterhus
c9b175992c Zend: Use true / false instead of 1 / 0 for bool parameters
Changes done with Coccinelle:

    @r1@
    identifier F;
    identifier p;
    typedef bool;
    parameter list [n1] PL1;
    parameter list [n2] PL2;
    @@

    F(PL1, bool p, PL2) {
    ...
    }

    @r2@
    identifier r1.F;
    expression list [r1.n1] EL1;
    expression list [r1.n2] EL2;
    @@

    F(EL1,
    (
    - 1
    + true
    |
    - 0
    + false
    )
    , EL2)
2025-09-24 18:51:40 +02:00
Tim Düsterhus
c32fbca874 Zend: Use true / false instead of 1 / 0 when assigning to bool
Changes done with Coccinelle:

    @@
    bool b;
    @@

    - b = 0
    + b = false

    @@
    bool b;
    @@

    - b = 1
    + b = true
2025-09-24 18:51:40 +02:00
Tim Düsterhus
f08fe17a53 Merge branch 'PHP-8.4'
* PHP-8.4:
  zend_API: Do not overwrite `readonly` properties in `object_properties_load()` (#19767)
2025-09-09 19:36:00 +02:00
Tim Düsterhus
9b71c61632 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  zend_API: Do not overwrite `readonly` properties in `object_properties_load()` (#19767)
2025-09-09 19:34:32 +02:00
Tim Düsterhus
215ebbb8d5 zend_API: Do not overwrite readonly properties in object_properties_load() (#19767)
Fixes php/php-src#19765.
2025-09-09 19:33:45 +02:00
Niels Dossche
9d8f2a4f4d Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-19720: Assertion failure when error handler throws when accessing a deprecated constant
2025-09-06 00:01:52 +02:00
Niels Dossche
c58312462c Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-19720: Assertion failure when error handler throws when accessing a deprecated constant
2025-09-06 00:01:13 +02:00
Niels Dossche
9d69ab91ab Fix GH-19720: Assertion failure when error handler throws when accessing a deprecated constant
When deprecation causes an exception, we should return NULL instead of
continuing.

Closes GH-19723.
2025-09-06 00:00:52 +02:00
Gina Peter Banyard
f4e2e91d4b core: Remove disable_classes INI setting
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#remove_disable_classes_ini_setting

This took longer to merge than expected but the initial motivation from 2 years ago still applied:

As described in the email to the PHP internals list [1] this feature is fundamentally broken and pointless.

Only internal classes can be disable which brings the following observation. On a minimal build of PHP, with only the mandatory extensions enabled, there are 148 classes/interfaces/traits defined. [2]

Other than the SPL ones (and even then), disabling any of these classes will cause issues within the engine.
Moreover, the SPL ones are not a security concern.

Therefore, any other class that can be disabled must come from an extension that can be disabled altogether. And "disabling" a class from an extension without disabling said extension will render it useless anyway.

If a hosting provided is concerned about an extension, then it should not enable it in the first place. Not break it ad hoc.

Considering the above, I cannot see how this functionality was ever useful.

This is in stark contrast to the disable_functions INI setting, which can be used to selectively remove functionality of an extension without breaking it overall.

What makes this setting particularly broken is that it does not unregister the class, it only overwrites the create CE handler to emit a warning and purge the properties and function hashtables. This leads to various use after free, segfaults, and broken expectations for the engine and extensions which define said classes. On top of that, it is possible to actually instantiate such a class (and even classes which actually disallow this like ext/imap) in userland, and pass it to function that are typed against said class without raising a TypeError. However, when trying to do anything with said object stuff is going to explode in countless ways.

[1] https://news-web.php.net/php.internals/120896
[2] https://gist.github.com/Girgias/63d55ba1e50b580412b004046daed02b
2025-08-25 21:16:55 +01:00
Alexandre Daubois
dfa1307a64 Various return types and values consolidation (#19418) 2025-08-12 11:28:41 +01:00
Tim Düsterhus
78d96e94fa zend_API: Make scope a const zend_class_entry* for zend_update_property_*() (#19156)
Follow-up for php/php-src#19060.
2025-07-17 22:11:24 +02:00
Tim Düsterhus
b43a7ac0e7 Zend: Make EG(fake_scope) a const zend_class_entry* (#19060) 2025-07-09 11:55:53 +02:00
Tim Düsterhus
45d948f2da Zend: Add zend_check_method_accessible() to DRY method visibility checks (#18995)
* Zend: Add `zend_check_method_accessible()` to DRY method visibility checks

* Zend: Add assertions verifying flags didn't change before `zend_check_method_accessible()`

* Try `zend_always_inline` for `zend_check_method_accessible`
2025-07-07 21:30:13 +02:00
Gina Peter Banyard
f91f80ca19 Zend: Return anonymous closure names in zend_get_callable_name_ex() (#19011)
This returns the usual `{closure:FILE_NAME/FUNCTION:LINE_NO}` for anonymous functions rather than `Closure::__invoke` this is visible for `is_callable()` and any Engine call that uses `zend_fcall_info_init()` to get the name of the callable.

Related to GH-18063.
2025-07-03 12:01:11 +01:00
Tim Düsterhus
ca49a7bec2 RFC: Turn clone() into a function (#18919)
RFC: https://wiki.php.net/rfc/clone_with_v2

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-06-24 20:14:40 +02:00
Daniil Gentili
591b3249da Do not use RTLD_DEEPBIND if dlmopen is available (#18612)
DL_LOAD now doesn't use RTLD_DEEPBIND deepbind anymore on platforms
where dlmopen with LM_ID_NEWLM is available:
this means shared library symbol isolation (if needed) must be enabled on
the user side when requiring libphp.so, by using dlmopen with LM_ID_NEWLM
instead of dlopen.
RTLD_DEEPBIND is still enabled when the Apache SAPI is in use.

Closes GH-10670.
2025-06-23 21:44:58 +02:00
DanielEScherzer
cd751f98cb Reapply GH-17712 with a fix for internal class constants (#18464)
Add recursion protection when emitting deprecation warnings for class
constants, since the deprecation message can come from an attribute that is
using the same constant for the message, or otherwise result in recursion.

But, internal constants are persisted, and thus cannot have recursion
protection. Otherwise, if a user error handler triggers bailout before the
recursion flag is removed then a subsequent request (e.g. with `--repeat 2`)
would start with that flag already applied. Internal constants can presumably
be trusted not to use deprecation messages that come from recursive attributes.

Fixes GH-18463
Fixes GH-17711
2025-05-25 16:43:36 -07:00
Ilija Tovilo
386ab1dad2 Revert "Fix infinite recursion on deprecated attribute evaluation"
This reverts commit 272f7f75e2.

Reverts GH-17712 for the PHP-8.4 branch. This will be reapplied later
with a fix for GH-18463 (GH-18464).
2025-04-30 20:52:56 +02:00
Gina Peter Banyard
71da944c82 Zend: Add MUTABLE zend_type foreach macros and const qualifiers
The motivation for this is that types should be considered immutable.
The only times this is not valid is during compilation, optimizations (opcache), or destruction.

Therefore the "normal" type foreach macros are marked to take const arguments and we add mutable version that say so in the name.
Thus add various const qualifiers to communicate intent.
2025-04-07 12:52:40 +01:00
Tim Düsterhus
5544be7018 RFC: Marking return values as important (#[\NoDiscard]) (#17599)
RFC: https://wiki.php.net/rfc/marking_return_value_as_important

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-04-02 09:35:29 +02:00
Ilija Tovilo
99f72fa499 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix infinite recursion on deprecated attribute evaluation
2025-03-26 23:40:58 +01:00
Ilija Tovilo
272f7f75e2 Fix infinite recursion on deprecated attribute evaluation
Fixes GH-17711
Fixes GH-18022
Closes GH-17712
2025-03-26 23:39:38 +01:00
Ilija Tovilo
076811af68 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix segfault when evaluating const expr default value of child prop with added hooks
2025-03-23 16:35:21 +01:00
Ilija Tovilo
d5bdf8f508 Fix segfault when evaluating const expr default value of child prop with added hooks
Introduced by GH-17870. Not adding a NEWS entry since this is fixed in
the same version.

Fixes oss-fuzz #403816122
Closes GH-18098
2025-03-23 16:35:04 +01:00
Tim Düsterhus
6962540662 zend_get_callable_name: Return underlying callable’s name for fake closures (#18063)
Fixes php/php-src#18062
2025-03-17 13:55:24 +01:00
Arnaud Le Blanc
f75dd82866 Merge branch 'PHP-8.4'
* PHP-8.4:
  Destroy temporary module classes in reverse order
2025-03-14 10:51:50 +01:00
Arnaud Le Blanc
4b9c72f329 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Destroy temporary module classes in reverse order
2025-03-14 10:49:10 +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
Gina Peter Banyard
65d433161a Use new known "self" and "parent" zend_strings (#17766) 2025-02-12 15:30:55 +00:00
Niels Dossche
b068c2ff94 Fix GH-17442: Engine UAF with reference assign and dtor
Closes GH-17443.
2025-01-30 19:43:03 +01:00