1131 Commits
Author SHA1 Message Date
Ilija Tovilo 9705fda1bb Merge branch 'PHP-8.6' into master
* PHP-8.6:
  Add NEWS entry
  Avoid state corruption via bailout
2026-10-21 16:34:56 +02:00
Ilija Tovilo d6373dfe15 Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
  Add NEWS entry
  Avoid state corruption via bailout
2026-10-21 16:33:23 +02:00
Ilija Tovilo c7273b9ba8 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Add NEWS entry
  Avoid state corruption via bailout
2026-10-21 16:30:04 +02:00
Ilija Tovilo 8a94bb3822 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Add NEWS entry
  Avoid state corruption via bailout
2026-10-21 16:27:03 +02:00
Ilija Tovilo c1a5f468d0 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Add NEWS entry
  Avoid state corruption via bailout
2026-10-21 16:12:35 +02:00
3584a98bda Avoid state corruption via bailout
- Replace bailout on OOM with UnwindExit
- Properly reset various globals that may be accessed during startup

Fix GHSA-w8hw-w9fx-j79w (CVE-2026-109618)
Fix GHSA-6wmf-4rv5-p3rp (CVE-2026-109619)

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Jakub Zelenka <bukka@php.net>
Co-authored-by: Nora Dossche <7771979+ndossche@users.noreply.github.com>
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
2026-10-21 16:06:22 +02:00
ndossche 12df767920 Merge branch 'PHP-8.6'
* PHP-8.6:
  phpdbg: Fix wrong command names
2026-10-11 01:38:27 +02:00
ndossche 96de5492c8 Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
  phpdbg: Fix wrong command names
2026-10-11 01:38:22 +02:00
ndossche 0adf274615 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  phpdbg: Fix wrong command names
2026-10-11 01:38:04 +02:00
ndosscheandWeilin Du f735f33d49 phpdbg: Fix wrong command names
Closes GH-24054.

Co-authored-by: Weilin Du <weilindu@php.net>
2026-10-11 01:37:26 +02:00
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
Tim Düsterhus 83e2394dc7 zend_portability: Simplify definition of ZEND_NORETURN (#23908) 2026-09-29 14:24:35 +02:00
Calvin Buckley 20f4c4d605 sapi: Remove sapi_terminate_process (#23524)
This is unused; this is a vestige of 6c158374ba
and 45e327a672, which set up some timeout code
which was removed in 650c1c0a7d. Remove this
useless function from SAPIs.
2026-09-28 15:06:30 -03:00
Dmytro Kulyk 67135cb97b gen_stub: Conditionally include zend_attributes.h to arginfo based on usage (#21570)
Headers required by the generated code (zend_attributes.h, zend_constants.h, zend_enum.h) are collected during generation and emitted as includes at the top of the arginfo file, with the same preprocessor conditions and PHP version guards as the code that needs them.

Removes the manual zend_attributes.h and zend_enum.h includes from sources that only needed them for the arginfo file they include.
2026-09-06 21:25:20 +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
Arnaud Le Blanc 9d6fd4fd98 Fix double free of phpdbg watch element chains
PHPDBG_G(watch_recreation) is keyed by element->str, so a watch element and
its implicit parent are stored under distinct keys ("$lower[0]" and
"$lower[]"). The deduplication in phpdbg_queue_element_for_recreation() only
walks down from the entry found under the *same* key, so it never notices
that the two belong to the same chain and both get queued.

phpdbg_free_watch_element_tree() frees the element together with its entire
parent and child chains, so draining watch_recreation freed that chain twice:
the first entry frees the whole chain, the second one then walks the already
freed links and frees them again.

Drop every entry referencing a member of the chain before freeing it. The
buckets are nulled out rather than deleted, as all callers are iterating over
the hash at that point; they clean it right afterwards.
2026-08-27 13:25:07 +02:00
Osama Aldemeery e721b3fdc3 Deprecate returning from a finally block. (#22509)
RFC: https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_returning_from_a_finally_block
2026-08-18 20:09:21 +01:00
Jorg Adam Sowa 87b510be6f Use zend_hash_find_ptr_lc() for case-insensitive name lookups (batch 2) (#22591)
Continues #22565 for four sites that were missed: _class_exists_impl(),
function_exists(), pdo_stmt.c's dbstmt_method_get(), ReflectionClass::
hasMethod()/getMethod(), and phpdbg's print func/method commands. No
behavior change.
2026-08-03 13:27:32 +01:00
Gina Peter Banyard 6877f77c62 main: convert last_error_lineno global to type uint32_t
As this is the expected type for lineno everywhere else in the engine
2026-07-30 09:45:57 +01:00
Weilin Du 00f4cd6b80 Refactor various raw C-string concatenation to use existing API (#22879)
In #21607 we introduce several inline helpers for raw C-string concatenation.
This PR use them to refactor several manual C string construction.
2026-07-25 01:06:29 +08:00
Ilia Alshanetsky 250f138329 Fix phpdbg over-read when watching a packed array element (#22756)
phpdbg watched every array element as a Bucket, but packed arrays store
bare zvals and de-indirected stack variables aren't buckets, so reading
Bucket.h/.key over-read the neighbour and a sibling write tripped a
phantom break. Watch such elements as WATCH_ON_ZVAL and compare the type
info first, reading the value union only for initialised slots so an
uninitialised CV is never compared by value.

A separate pre-existing bug crashed 32-bit: phpdbg_btree_insert_or_update
linked each new node into the tree before initialising its child
pointers, so a write to a node on a watched page faulted into the
watchpoint handler, which walked the half-built node. Build the node
fully, then publish it with a single store.

Closes GH-22756
2026-07-24 11:14:15 -04:00
Gina Peter Banyard 34c686a5b4 stream: remove path parameter in stream error functions (#22792)
Instead rely on the mechanism gated by the error_include_args INI to display them.

This actually aligns the behaviour of what was accepted in https://wiki.php.net/rfc/display_error_function_args.
2026-07-19 16:15:01 +01:00
Ilia Alshanetsky 207dd1d23f Fix GH-22480: phpdbg use-after-free re-watching a watched variable (#22493)
phpdbg_add_watch_element() frees the passed element and returns the
existing one when the variable is already watched, but several callers
kept using the freed pointer, so re-watching a variable was a
use-after-free in more places than the two reported. Report the duplicate
back through the parse callback and register nothing, and reject a
recursive watch's hashtable element that collides with an existing watch,
at creation and recreation, rather than freeing a still-referenced one. A
recursive watch over an already-array-watched variable now watches only
the root and skips the shared hashtable.

Running the tests under ASAN exposed a second, latent use-after-free at
shutdown: the watch tables are module-scoped but hold request-pool memory,
so under the tracked allocator freeing a watched variable during executor
teardown re-queues an element after the last drain, tracked_free_all frees
the pool, and phpdbg_destroy_watchpoints reads it at module shutdown. Tear
the watch state down in a post_deactivate handler, which runs after the
executor frees values but before the memory manager is torn down.

Dropping watch_006's xfail surfaced a separate pre-existing bug on
large-page platforms: the fault handler rechecks every watchpoint on the
faulting page, so on 16 KB pages a value-only write to an element can
fault the page holding a watched hashtable's own struct and run the
recursive rescan, which re-reported existing elements as freshly added.
Only run that rescan when the element count actually changed.

Fixes GH-22480
2026-07-14 14:23:34 -04:00
Jorg Adam Sowa e7eebb9b1e sapi/phpdbg: remove dead str_type assignments before goto (#22600)
The switch in phpdbg_print_breakpoints() assigned str_type per case
and jumped to a shared label that immediately recomputed the same
value from brake->type, making the pre-goto assignments dead. Set
str_type directly per case instead and drop the goto.
2026-07-08 15:40:23 +01:00
Tim Düsterhus dcfa40cccf Merge branch 'PHP-8.5'
* PHP-8.5:
  phpdbg: Fix off-by-one in phpdbg_safe_class_lookup() signal-safe class lookup (#22593)
2026-07-04 20:08:51 +02:00
Tim Düsterhus 88193e511b Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  phpdbg: Fix off-by-one in phpdbg_safe_class_lookup() signal-safe class lookup (#22593)
2026-07-04 20:07:59 +02:00
Jorg Adam Sowa 21bf7f67ff phpdbg: Fix off-by-one in phpdbg_safe_class_lookup() signal-safe class lookup (#22593)
lc_length was set to name_length + 1, one past the actual lowercased
string length, so zend_hash_str_find_ptr() (which expects a strlen-style
length) never matched an existing class entry. This made class lookups
during phpdbg's signal-handler interruption path always fail silently.

Replaced the manual emalloc/tolower/efree dance with
zend_hash_str_find_ptr_lc(), which performs the lowercase copy and
lookup in one call and removes the surface for this class of bug.
2026-07-04 20:07:49 +02: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
Gina Peter Banyard 092de40341 Merge branch 'PHP-8.5'
* PHP-8.5:
  phpdbg: fix leaked lowercased lookup keys in phpdbg_resolve_opline_break
2026-07-03 01:17:51 +01:00
Gina Peter Banyard 00aa0e39c3 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  phpdbg: fix leaked lowercased lookup keys in phpdbg_resolve_opline_break
2026-07-03 01:17:06 +01:00
Jorg Sowa b6938a25ee phpdbg: fix leaked lowercased lookup keys in phpdbg_resolve_opline_break
phpdbg_resolve_opline_break() passed the result of zend_str_tolower_dup()
directly as the lookup key to zend_hash_str_find_ptr() for both the class
and the function/method lookups. That emalloc'd buffer was never freed,
leaking on every method/function opline breakpoint resolution.

Use zend_hash_str_find_ptr_lc(), which lowercases into a (stack-allocated
for short names) temporary and frees it internally, instead of duplicating
the key by hand and leaking it.

Add a regression test that exercises all three paths through the two
lookups (class + method found, method not found, class not found).

Closes GH-22563
2026-07-03 01:15:56 +01:00
Jorg Adam Sowa 39b66bae33 Use zend_hash_find_ptr_lc() for case-insensitive name lookups (#22565)
A number of call sites lowercased a class/function/method name into a
temporary string solely to use it as a lookup key in the class table,
function table, module registry, etc., then released it. Replace those
with zend_hash_find_ptr_lc() / zend_hash_str_find_ptr_lc(), which
lowercase into a stack buffer (for short names), perform the lookup, and
free the temporary internally.

This removes the manual tolower + release boilerplate at 17 sites and
avoids a heap allocation for the common short-name case. No behavior
change.
2026-07-03 00:53:33 +01:00
Ilia Alshanetsky 10f1d04831 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-17387: crash on unterminated quote in phpdbg lexer
2026-06-29 07:04:07 -04:00
Ilia Alshanetsky d92b5f9d1c Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-17387: crash on unterminated quote in phpdbg lexer
2026-06-29 07:03:55 -04:00
Ilia Alshanetsky 2e564a747c Fix GH-17387: crash on unterminated quote in phpdbg lexer
In the NORMAL condition a lone unterminated quote matched no rule, so
re2c backtracked to a zero-length GENERIC_ID accept. The rule body then
computed yyleng - unescape_string(yytext) as 0 - N, underflowing size_t
into a multi-gigabyte estrndup. Give a bare quote an explicit
one-character accept so the cursor advances and unescape_string is never
reached with a malformed token.

Fixes GH-17387
Closes GH-22506
2026-06-29 06:39:54 -04: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
Tim Düsterhus 7114314c5a tree-wide: Replace XtOffsetOf by its definition (#21899)
`offsetof()` is in `stddef.h` and thus always available. The extra macro is an
unnecessary layer of indirection.
2026-04-28 22:12:56 +02:00
Ben Ramsey f414d448b9 license-update: man pages
RFC: https://wiki.php.net/rfc/php_license_update
2026-04-11 21:20:54 -05: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
Tim Düsterhus 04f06e8cf2 zend_portability: Remove EMPTY_SWITCH_DEFAULT_CASE() (#20063)
There are several issues with this macro:

- It is incorrectly named: It's not an empty default case. It's an unreachable
  default case.
- It is hiding control flow in its definition, which can be confusing for
  humans and tools (such as Coccinelle) alike, because it looks like it would
  be a statement that belongs to the "current" case rather than opening a new
  one.

Since this macro is exactly as long as explicitly spelling out its definition
(excluding the useless `break;`), it is not even making the code any more
succinct.
2026-04-06 14:46:15 +02: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
Peter Kokot 3927630e62 Remove unused config.h inclusion in SAPIs (#21377)
Current PHP SAPIs aren't built outside of php-src and neither is
anywhere described how such configuration header is supposed to be used.
2026-03-15 12:57:20 +01:00