1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Commit Graph

728 Commits

Author SHA1 Message Date
Arnaud Le Blanc
d16e6f52a4 Generate C enums from internal enums, introduce Z_PARAM_ENUM() (#20917)
Update gen_stubs.php to generate C enums from internal enums, when the stub is annotated with @generate-c-enums. Enum values can be compared to the result of zend_enum_fetch_case_id(zend_object*).

The generated enums are added to separate files named {$extensionName}_decl.h, so that it's possible to include these from anywhere. _arginfo.h files would generate warnings if we tried to include them in a compilation unit that doesn't call the register_{$class} functions, for instance.

Introduce Z_PARAM_ENUM().

* Make ZEND_AST_CONST_ENUM_INIT a 4-children node

* Store enum case id in ZEND_AST_CONST_ENUM_INIT

* Store enum case id in instance

* Expose enum case_id internally

* Generate C enum for internal enums

* Introduce Z_PARAM_ENUM()

* Port extensions
2026-02-03 12:38:04 +01: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
Tim Düsterhus
db8d35e7eb tree-wide: Replace ZEND_WRONG_PARAM_COUNT() by its definition (#20066)
* tree-wide: Replace `WRONG_PARAM_COUNT` by `ZEND_WRONG_PARAM_COUNT()`

This is a direct alias.

* tree-wide: Replace `ZEND_WRONG_PARAM_COUNT()` by its definition

This macro was hiding control flow (the return statement) and thus was
particularly unhygienic.
2025-11-12 21:28:56 +01:00
Gina Peter Banyard
ccda8b16d4 zend_API.c: add const qualifiers 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
c669fbf370 Zend/zend_compile: add const qualifiers 2025-10-30 12:02:43 +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
Tim Düsterhus
6da93a86f2 zend_API: Remove CHECK*NULL_PATH (#20155)
* tree-wide: Replace `CHECK_NULL_PATH()` by `zend_char_has_nul_byte()`

The former is a direct alias of the latter with a more explicit name and the
former is explicitly documented as a “compatibility” alias.

* tree-wide: Replace `CHECK_ZVAL_NULL_PATH()` by its definition

The former is explicitly documented as a “compatibility” alias.

* zend_API: Remove `CHECK*NULL_PATH`

The `CHECK_ZVAL_NULL_PATH()` macro is unsafe, because it implicitly assumes
that the given `zval*` is `IS_STRING`.

Based on a GitHub search there does not seem to be any user outside of PHP, all
hits were just forks / copies of php-src.
2025-10-15 10:24:22 +02:00
Tim Düsterhus
f566312b54 zend_API: Remove ZVAL_IS_NULL() (#19986)
The `ZVAL_*()` macros are setters, the `Z_*()` macros are getters.
2025-09-29 12:35:22 +02:00
Gina Peter Banyard
ba4a12bc39 Zend: add const qualifier for scope in read property functions (#19949) 2025-09-24 18:53:50 +01:00
Ilija Tovilo
5897071ab6 Fix refcounting on zend_empty_array in ext-uri (GH-19908)
Fixes GH-19892
2025-09-21 21:56:04 +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
Gina Peter Banyard
105c1e9896 tree: use zend_str_has_nul_byte() API (#19336) 2025-07-31 23:57:27 +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
Kasey Jenkins
cea0918352 Fix empty_fcall_info C++ missing-field-initializers warning (GH-19084)
Closes GH-19085
2025-07-10 11:02:39 +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
Ilija Tovilo
16c4c066f4 Make empty_fcall_info and empty_fcall_info_cache macros
See https://github.com/php/php-src/pull/18273, a constant may cause
unnecessary cache misses.

Closes GH-18326
2025-04-15 12:51:10 +02: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
Niels Dossche
08b14a57b8 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17162: zend_array_try_init() with dtor can cause engine UAF
2024-12-15 20:12:12 +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
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 Bnayard
5853cdb73d Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
Gina Peter Bnayard
96d572a18e Zend: Add helper for "cannot be empty" ValueError 2024-08-21 21:12:17 +01:00
Gina Peter Banyard
51379d66ec Zend: Add object_init_with_constructor() API (#14440)
This will instantiate the object and execute its constructor with the given parameters.
2024-06-06 21:21:16 +01:00
Tim Düsterhus
c2a9166ef0 Merge branch 'PHP-8.3'
* PHP-8.3:
  Make the `fcc` parameter `const` in `zend_call_known_fcc` (#14259)
2024-05-17 16:14:45 +02:00
Tim Düsterhus
a89d22cc0c Make the fcc parameter const in zend_call_known_fcc (#14259)
This makes it legal to call the function from a caller that only has a `const`
pointer to the `fcc` to prevent accidental modification.
2024-05-17 16:14:16 +02:00
Ilija Tovilo
1c30c5e707 Print location on class redeclaration
Fixes GH-13950
Closes GH-13999
2024-04-30 14:34:43 +02:00
Arnaud Le Blanc
fd73681c86 Fix GCC warning when using getThis() in a conditional (#13923)
Since GCC 12.x, using getThis() in a conditional yields a warning:

    <source>:12:22: warning: the comparison will always evaluate as 'true' for
                    the address of 'This' will never be NULL [-Waddress]
       12 |     return getThis() ? 2 : 3;
          |                      ^
2024-04-09 19:09:07 +02:00
Máté Kocsis
f2e199e878 Implement "support doc comments for internal classes and functions" (#13266)
Fixes #13130
2024-02-25 08:41:31 +01:00
Ilija Tovilo
631bc81607 Implement stackless internal function calls
Co-authored-by: Dmitry Stogov <dmitry@zend.com>

Closes GH-12461
2024-02-06 17:42:28 +01:00
Niels Dossche
345ac90eac Introduce Z_PARAM_FUNC_EX2 to maintain compatibility (#12419)
Commit d86314939c added an additional parameter to Z_PARAM_FUNC_EX.
To maintain compatibility with third-party extensions, we keep
Z_PARAM_FUNC_EX as it used to be, and add Z_PARAM_FUNC_EX2 instead.
2023-10-11 19:55:00 +02:00
George Peter Banyard
d86314939c Zend: Add ZPP F type check for callables that do not free trampolines
As refetching it with the new FCC API does get tedious
2023-10-10 13:44:21 +01:00
Niels Dossche
8a812c3fda Fix GH-12215: Module entry being overwritten causes type errors in ext/dom (PHP 8.4)
When we try to load an extension multiple times, we still overwrite the
type, module number, and handle. If the module number is used to
indicate module boundaries (e.g. in reflection and in dom, see e.g.
dom_objects_set_class_ex), then all sorts of errors can happen.

In the case of ext/dom, OP's error happens because the following
happens:
- The property handler is set up incorrectly in
  dom_objects_set_class_ex() because the wrong module number is
  specified. The class highest in the hierarchy is DOMNode, so the
  property handler is incorrectly set to that of DOMNode instead of
  DOMDocument.
- The documentElement property doesn't exist on DOMNode, it only exists
  on DOMDocument, so it tries to read using zend_std_read_property().
  As there is no user property called documentElement, that read
  operation returns an undef value.
  However, the type is still checked, resulting in the strange exception.

Solve this by changing the API such that the data is only overwritten if
it's owned data.

Closes GH-12246.
2023-09-20 21:02:51 +02:00
George Peter Banyard
80e90ad7ba Add number or str ZPP macros 2023-06-18 13:09:03 +01:00
Ilija Tovilo
6f63d4b274 Fix -Wenum-int-mismatch warnings on gcc 13
Closes GH-11103
2023-04-20 16:04:59 +02:00
Máté Kocsis
414f71a902 Typed class constants (#10444)
RFC: https://wiki.php.net/rfc/typed_class_constants

Co-Authored-By: Ben <7127204+moliata@users.noreply.github.com>
Co-Authored-By: Bob Weinand <3154871+bwoebi@users.noreply.github.com>
Co-Authored-By: Ilija Tovilo <ilija.tovilo@me.com>
2023-04-16 22:20:26 +02:00
Dmitry Stogov
0e70693701 Revert "Zend/zend_types.h: move IS_* to zend_type_code.h"
This reverts commit 0270a1e54c.
2023-04-04 22:48:26 +03:00
Dmitry Stogov
61b19ba3f0 Revert "Zend/zend_types.h: move zend_uchar.h to zend_char.h"
This reverts commit 42577c6b6b.
2023-04-04 22:47:45 +03:00
Derick Rethans
78937c93ef Merge branch 'PHP-8.2' 2023-03-09 13:39:31 +00:00
Derick Rethans
a45bef0ac6 Merge branch 'PHP-8.1' into PHP-8.2 2023-03-09 13:37:19 +00:00
Derick Rethans
717335ec63 Fixed macro generation for variadics, which don't have a default value 2023-03-09 11:39:22 +00:00
Derick Rethans
792400bc68 Merge branch 'PHP-8.2' 2023-03-03 16:52:51 +00:00
Derick Rethans
bbcc1dadea Merge branch 'PHP-8.1' into PHP-8.2 2023-03-03 16:52:26 +00:00
Derick Rethans
7fcea9d260 Add missing ZEND_ARG_VARIADIC_OBJ_TYPE_MASK macro, and use consistent class_name variable name 2023-03-03 16:51:51 +00:00
Max Kellermann
42577c6b6b Zend/zend_types.h: move zend_uchar.h to zend_char.h
Prepare to fix the cyclic header dependency from `zend_string.h`.
2023-02-26 14:16:53 +00:00
Max Kellermann
0270a1e54c Zend/zend_types.h: move IS_* to zend_type_code.h
More decoupling of circular header dependencies.
2023-02-26 14:16:53 +00:00
Max Kellermann
413844d626 Zend/zend_types.h: deprecate zend_bool, zend_intptr_t, zend_uintptr_t (#10597)
These types are standard C99.

For compatibility with out-of-tree extensions, keep the typedefs
in main/php.h.
2023-02-18 19:31:28 +00:00
Máté Kocsis
7936c8085e Fix GH-8329 Print true/false instead of bool in error and debug messages (#8385) 2023-01-23 10:52:14 +01:00