247 Commits
Author SHA1 Message Date
Nora Dossche 4e131c008d phpdbg: Remove stale check (#24055)
This is always false, see GH-24038.
2026-10-10 13:43:55 +02:00
Marc 37d0ef5a66 Zend: Remove zend_atomic.[ch] abstraction (#23927) 2026-09-29 16:30:30 +02:00
Dmitry Rantovov 1d82b6f0d7 sapi/phpdbg: restore the DEFAULT_SLASH check on the module path (#23583)
The move to memchr() in GH-21578 changed:
`if (strchr(*path, '/') != NULL || strchr(*path, DEFAULT_SLASH) != NULL) {`
to
`if (memchr(ZSTR_VAL(*path), '/', ZSTR_LEN(*path)) != NULL || memchr(ZSTR_VAL(*path), '/', ZSTR_LEN(*path)) != NULL) {`
instead of
`if (memchr(ZSTR_VAL(*path), '/', ZSTR_LEN(*path)) != NULL || memchr(ZSTR_VAL(*path), DEFAULT_SLASH, ZSTR_LEN(*path)) != NULL) {`

Fix this.
2026-09-06 13:34:37 +01:00
Weilin Du 3afe4e3ede Remove various useless #include (#22581)
This removes leftover win32/param.h / <sys/param.h> includes from files that
do not use any of the macros provided by those headers (MAXPATHLEN,
MAXHOSTNAMELEN, howmany, roundup).

It also removes local Windows O_RDONLY -> _O_RDONLY aliases from files where
O_RDONLY is not used.
2026-07-04 19:52:47 +08:00
Ilija Tovilo 529b145511 Merge branch 'PHP-8.5'
* PHP-8.5:
  GHSA-m8rr-4c36-8gq4: Consistently pass unsigned char to ctype.h functions
2026-05-06 13:11:01 +02:00
Ilija Tovilo b8dad9314c GHSA-m8rr-4c36-8gq4: Consistently pass unsigned char to ctype.h functions
Fixes GHSA-m8rr-4c36-8gq4
Fixes CVE-2026-7258
2026-05-06 13:10:12 +02:00
Ilija Tovilo dc9e21b81c GHSA-m8rr-4c36-8gq4: Consistently pass unsigned char to ctype.h functions
Fixes GHSA-m8rr-4c36-8gq4
Fixes CVE-2026-7258
2026-05-06 13:09:23 +02:00
Ilija Tovilo 398b7dabfb GHSA-m8rr-4c36-8gq4: Consistently pass unsigned char to ctype.h functions
Fixes GHSA-m8rr-4c36-8gq4
Fixes CVE-2026-7258
2026-05-06 13:08:17 +02:00
Ilija Tovilo a38418777f GHSA-m8rr-4c36-8gq4: Consistently pass unsigned char to ctype.h functions
Fixes GHSA-m8rr-4c36-8gq4
Fixes CVE-2026-7258
2026-05-06 13:07:20 +02:00
Ilia Alshanetsky e228395787 Use pemalloc/perealloc for persistent allocations
Replace direct malloc/realloc calls with OOM-safe pemalloc/perealloc
(persistent: true) counterparts.

Fixes GH-19200
Fixes GH-17013
Closes GH-21625
2026-05-03 13:08:54 -04:00
Ben Ramsey e1984cbd06 license-update: sapi/phpdbg source headers
RFC: https://wiki.php.net/rfc/php_license_update
2026-04-11 21:20:54 -05:00
Marc Bennewitz f4d9ed1368 Use consistent type for h on call zend_hash_index_* (#19255) 2026-04-06 14:39:41 +01:00
Gina Peter Banyard a231da8d28 sapi/phpdbg: refactor phpdbg_load_module_or_extension() (#21578)
Accept a zend_string* to be able to use the zend_string_concat APIs
Make the function static as it's not exported in a header and only used inside this file
2026-03-31 18:40:32 +01:00
Gina Peter Banyard cd753007ce Audit INI functions and macros, and replace them with better alternatives (#21146)
Audit zend_ini_string(), INI_STR(), and related functions and macros, and all other INI_* macros.

The primary motivation is that these APIs should return a `const char*` because the `char*` is owned by a zend_string, and thus should never be released.

Moreover, the INI_STR() API doesn't follow our usual naming scheme as it returns a char* rather than a zend_string*.

In this PR new zend_ini_{bool|long|double|str|string}_literal() macros are introduced replacing the INI_{BOOL|INT|FLT|STR} macros which follow our more modern naming convention.
Moreover, the INI_BOOL() macro didn't produce correct values if the INI string is a word like "true" or "on".

The INI_ORIG_* APIs are removed because a Sourcegraph search shows 0 results, other than the one case used in ext/tidy that we fix using the typical API.

Add some additional checks for the value of an INI string to ensure it doesn't contain a nul byte when describing a path.
2026-03-30 14:48:12 +01:00
Ilija Tovilo 084e409694 Remove zend_exception_save() and zend_exception_restore()
These are leftovers from the pre-PHP-7.0 era. This also implicitly solves
GH-20564 by not clearing exceptions before entering the autoloader.

Closes GH-20256
Fixes GH-20564
2026-01-16 20:18:51 +01:00
Arnaud Le Blanc 73b98a3858 TAILCALL VM
Introduce the TAILCALL VM, a more efficient variant of the CALL VM:

 * Each opcode handler tailcalls the next opcode handler directly instead of
   returning to the interpreter loop. This eliminates call and interpreter loop
   overhead.
 * Opcode handlers use the preserve_none calling convention to eliminate
   register saving overhead.
 * preserve_none uses non-volatile registers for its first arguments, so
   execute_data and opline are usually kept in these registers and no code is
   required to forward them to the next handlers.

Generated machine code is similar to a direct-threaded VM with register pinning,
like the HYBRID VM.

JIT+TAILCALL VM also benefits from this compared to JIT+CALL VM:

 * JIT uses the registers of the execute_data and opline args as fixed regs,
   eliminating the need to move them in prologue.
 * Traces exit by tailcalling the next handler. No code is needed to forward
   execute_data and opline.
 * No register saving/restoring in epilogue/prologue.

The TAILCALL VM is used when the HYBRID VM is not supported, and the compiler
supports the musttail and preserve_none attributes: The HYBRID VM is used when
compiling with GCC, the TAILCALL VM when compiling with Clang>=19 on x86_64 or
aarch64, and the CALL VM otherwise.

This makes binaries built with Clang>=19 as fast as binaries built with GCC.
Before, these were considerably slower (by 2.8% to 44% depending on benchmark,
and by 5% to 77% before 76d7c616bb).

Closes GH-17849
Closes GH-18720
2025-08-22 18:05:52 +02:00
Gina Peter Banyard d9000b3094 tree: replace some unnecessary uses of spprintf (#19354) 2025-08-05 17:25:47 +01:00
Niels Dossche eb151e39b0 Properly handle reference return value from __toString()
It's possible to return a reference from __toString(), but this is not
handled and results in a (confusing) error telling that the return value
must be a string.
Properly handle this by unwrapping the reference.

Closes GH-18810.
2025-06-10 19:15:53 +02:00
Niels Dossche ef10339fe7 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix memory leak in phpdbg calling registered function
  Partially fix GH-17387
2025-01-30 19:32:28 +01:00
Niels Dossche 29bafa6323 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix memory leak in phpdbg calling registered function
  Partially fix GH-17387
2025-01-30 19:31:38 +01:00
ndossche 62bbfdebaa Fix memory leak in phpdbg calling registered function
Closes GH-17635.
2025-01-30 19:28:26 +01:00
Niels Dossche 2860c3d641 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix crashes in function registration + test
2025-01-06 21:31:03 +01:00
Niels Dossche 1235c74828 Fix crashes in function registration + test
Internal function won't need their refcount increased as they outlive
the debugger session, and userland functions won't be unloaded either.
So no refcount management is necessary for registered functions.
2025-01-06 21:30:34 +01:00
Gina Peter Banyard e2e7b46542 sapi/phpdbg: Grab the function pointer directly
Allocating a string zval to let zend_call_function() do the same thing is slightly pointless
2025-01-06 20:17:25 +00:00
Niels Dossche a58c6d56bb Make docs consistent with help text 2025-01-06 20:17:25 +00:00
Niels Dossche 8cb15f6203 Fix crashes in function registration + test
Internal function won't need their refcount increased as they outlive
the debugger session, and userland functions won't be unloaded either.
So no refcount management is necessary for registered functions.
2025-01-06 20:17:25 +00:00
Arnaud Le Blanc 443aa29dbe Support stack limit in phpdbg SAPI
Fixes GH-16041
Closes GH-16055
2024-10-03 15:22:51 +02:00
Christoph M. Becker 3c1af3febb Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16181: phpdbg: exit in exception handler reports fatal error
2024-10-03 11:39:03 +02:00
Christoph M. Becker 95c97c81b7 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16181: phpdbg: exit in exception handler reports fatal error
2024-10-03 11:37:15 +02:00
Christoph M. Becker f14e5cfaaa Fix GH-16181: phpdbg: exit in exception handler reports fatal error
When running PHP code, we must not handle `UnwindExit` exceptions, but
rather have to ignore them.

Closes GH-16182.
2024-10-03 11:36:13 +02:00
Gina Peter Banyard a79c70f574 [RFC] Convert exit (and die) from language constructs to functions (#13483)
RFC: https://wiki.php.net/rfc/exit-as-function
2024-08-14 12:44:12 +01:00
David Carlier 667a5651ca Merge branch 'PHP-8.3' 2024-08-09 21:15:07 +01:00
David Carlier de5c760c69 Merge branch 'PHP-8.2' into PHP-8.3 2024-08-09 21:12:34 +01:00
David Carlier 9aeb6761b5 Fix GH-15210: phpdbg_print_changed_zvals working on a real copy instead.
Close GH-15229
2024-08-09 21:12:11 +01:00
Niels Dossche dd0f2abc80 Use param->len instead of strlen 2023-12-18 13:53:57 +00:00
Niels Dossche e6e0231a98 Use asprintf return value for the size 2023-12-18 13:53:57 +00:00
Niels Dossche b198d0cc0c Use precomputed length for phpdbg_try_file_init() 2023-12-18 13:53:57 +00:00
Niels Dossche 61b7370b6d Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-12929: SimpleXMLElement with stream_wrapper_register can segfault
  Fix getting the address of an uninitialized property of a SimpleXMLElement resulting in a crash
  Fix GH-12962: Double free of init_file in phpdbg_prompt.c
2023-12-17 11:52:48 +01:00
Niels Dossche 4fc336c784 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix getting the address of an uninitialized property of a SimpleXMLElement resulting in a crash
  Fix GH-12962: Double free of init_file in phpdbg_prompt.c
2023-12-17 11:50:42 +01:00
Niels Dossche a6d17bffe1 Fix GH-12962: Double free of init_file in phpdbg_prompt.c
See GH-12962 for analysis.

Closes GH-12963.
2023-12-17 11:46:02 +01:00
Niels Dossche d882c5d580 Merge branch 'PHP-8.3'
* PHP-8.3:
  Use __DIR__-relative path in tests
  Fix GH-12675: MEMORY_LEAK in phpdbg_prompt.c
2023-11-15 22:01:05 +01:00
Niels Dossche c83632a503 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Use __DIR__-relative path in tests
  Fix GH-12675: MEMORY_LEAK in phpdbg_prompt.c
2023-11-15 22:00:44 +01:00
Niels Dossche 4f1103ef3b Fix GH-12675: MEMORY_LEAK in phpdbg_prompt.c
Have to use file_put_contents() instead of --FILE-- because we have to
actually load it using the exec command, *and* have to make multiple
files, and note that we can only load files relative from the current
directory, so we can't rely on files being in the sapi/phpdbg/tests
folder.

Closes GH-12680.
2023-11-15 21:59:55 +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 d5ad75108e More usage of known zend_str instead of C string (#11381) 2023-06-08 13:03:29 +01:00
Max Kellermann 7029fd08b1 Zend/zend_extensions: make zend_extension_version_info const (#10592)
A zend_extension_version_info is never written to.
2023-02-20 13:20:54 +00:00
George Peter Banyard b505562a45 Merge branch 'PHP-8.2' 2022-12-23 13:59:39 +00:00
George Peter Banyard 0100dbdaf8 Merge branch 'PHP-8.1' into PHP-8.2 2022-12-23 13:57:58 +00:00
Niels Dossche 5f1311a92c Fix undefined behaviour in phpdbg_load_module_or_extension
If zend_register_module_ex were to return NULL, then module_entry will
be set to NULL, and the if's body will load module_entry->name. Since
module_entry is NULL, loading the name would cause a NULL pointer
dereference. However, since a NULL pointer dereference is undefined
behaviour, the compiler is free to remove the check.
Fix it by using *name instead of module_entry->name.

Closes GH-10157

Signed-off-by: George Peter Banyard <girgias@php.net>
2022-12-23 13:55:50 +00:00
George Peter Banyard 66661ae682 Remove most usages of zend_fcall_info_args()
This reallocates the PHP array when one can just use the named_params fields to pass the positional arguments instead.

Only usage of zend_fcall_info_args(_ex) remains in PDO.
2022-10-21 18:31:40 +01:00