Commit Graph

18276 Commits

Author SHA1 Message Date
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
Arnaud Le Blanc
c767fec2d0
Fix crash during GC of suspended generator delegate (#15275) 2024-08-10 15:46:31 +02:00
Christoph M. Becker
423fc811bd
zend_enum: Rename try parameter to avoid conflict with C++
`try` is a keyword in C++, and as such C++ code including <zend_enum.h>
fails to compile unless a workaround is in place.  To resolve this, we
simply rename the parameter.

We choose `try_from` to make it clear that this parameter is true when
the function is called from `BackedEnum::tryFrom()`.  For consistency,
we also rename the `try` parameter of `zend_enum_from_base()`, although
that function is not exported.

This issue had been reported by @oplanre, who also provided an initial
PR.

Closes GH-15259.
2024-08-07 14:54:35 +02:00
Arnaud Le Blanc
99e0d3fe09
Fix destruction of generator running in fibers during shutdown (#15158)
The destructor of generators is a no-op when the generator is running in a fiber,
because the fiber may resume the generator. Normally the destructor
is not called in this case, but this can happen during shutdown.

We detect that a generator is running in a fiber with the
ZEND_GENERATOR_IN_FIBER flag.

This change fixes two cases not handled by this mechanism:

- The ZEND_GENERATOR_IN_FIBER flag was not added when resuming a "yield from $nonGenerator"

- When a generator that is running in a fiber has multiple children (aka multiple generators yielding from it), all of them could be considered to also run in a fiber (only one actually is), and could leak if not destroyed before shutdown.
2024-07-30 14:53:19 +02:00
Dmitry Stogov
d41e97ae66
Workaraound against false positive GCC array bounds error (#15078)
This prevents compilation error when compiling PHP by GCC with "-O2 -g -Wall -Werror"

zend_API.c:2754:34: error: array subscript ‘zend_function
{aka const union _zend_function}[0]’ is partly outside array bounds of
‘unsigned char[160]’ [-Werror=array-bounds=]

 2754 |         if (ZSTR_VAL(fptr->common.function_name)[0] != '_'
2024-07-24 08:21:16 +03:00
Bob Weinand
a18df90a8b Fix GH-13817: Segmentation fault for enabled observers after pass 4
Instead of fixing up temporaries count in between observer steps, just apply the additional temporary in the two affected observer steps.

Closes GH-14018.
2024-07-22 18:28:03 +02:00
Niels Dossche
8c19efdc97
Fix GH-15023: Memory leak in Zend/zend_ini.c
Closes GH-15024.
2024-07-19 14:57:19 +02:00
Niels Dossche
03d73182d9
Fix GH-15020: Memory leak in Zend/Optimizer/escape_analysis.c
Closes GH-15022.
2024-07-19 14:56:28 +02:00
Ilija Tovilo
b368db204f
Fix comments between -> and keyword
Comments should not fall out of ST_LOOKING_FOR_PROPERTY.

Fixes GH-14961
Closes GH-14976
2024-07-16 23:40:18 +02:00
Pierrick Charron
e07813ad46
PHP-8.2 is now for PHP 8.2.23-dev 2024-07-16 12:20:55 -04:00
Ilija Tovilo
8c312ba74b
Fix use-after-free in property coercion with __toString()
This was only partially fixed in PHP-8.3. Backports and fixes the case for both
initialized and uninitialized property writes.

Fixes GH-14969
Closes GH-14971
2024-07-16 12:40:14 +02:00
Niels Dossche
eb8c3cb79a
Fix GH-14741: Segmentation fault in Zend/zend_types.h
The create_obj handler of InternalIterator is overwritten, but not the
clone_obj handler. This is not allowed.
In PHP 8.2 this didn't cause a segfault because the standard object
handler was used for the clone instead of the internal handler.
So then it allocates and frees the object using the standard object handlers.
In 8.3 however, the object is created using the standard object handler and
freed using the custom handler, resulting in the buffer overflow.
Even though bisect points to 1e1ea4f this only reveals the bug.

Closes GH-14882.
2024-07-09 00:56:53 +02:00
Niels Dossche
8fd095669a
Factor out common check for short-circuited ast 2024-06-30 13:38:14 +02:00
Niels Dossche
d568337680
Fix OSS-Fuzz #69765: Yield reference to nullsafe chain
You cannot return or yield a reference to a nullsafe chain. This was
checked already in zend_compile_return but not yet in
zend_compile_yield.

Closes GH-14716.
2024-06-30 13:38:06 +02:00
David Carlier
c03196a5be
Fix GH-14712: segfault on invalid object.
If the extension does not allow to get a property pointer (like PDORow
object), we fallback
to the read property cb anyway.
2024-06-29 15:51:57 +01:00
Niels Dossche
056bec72f4
Fix GH-14590: Memory leak in FPM test gh13563-conf-bool-env.phpt
Values retrieved from zend_getenv should be freed.
Note: The only possible value for `zend_getenv` is `sapi_getenv` which uses
zend alloc to duplicate the string that it reads from the SAPI module.

Closes GH-14708.
2024-06-28 22:05:15 +02:00
Arnaud Le Blanc
1ff277dee2
Fix is_zend_ptr() for huge blocks (#14626)
is_zend_ptr() expected zend_mm_heap.huge_list to be circular, but it's in fact NULL-terminated. It could crash when at least one huge block exists and the ptr did not belong to any block.
2024-06-25 15:14:00 +02:00
Sergey Panteleev
49aaa7cd9f
PHP-8.2 is now for PHP 8.2.22-dev 2024-06-18 17:56:05 +03:00
Gina Peter Banyard
cdb7677b38
Fix bug GH-14456: Attempting to initialize class with private constructor calls destructor
Closes GH-14469
2024-06-06 15:50:41 +01:00
Dmitry Stogov
86b93bc479
Fix GH-14480: Method visibility issue introduced in version 8.3.8 (#14484) 2024-06-05 23:53:31 +03:00
Bob Weinand
be7f3aa474 Fix GH-14387: Crash when stack walking in destructor of yielded from values during Generator->throw() 2024-06-01 02:38:55 +02:00
Manuel Kress
272da51bfd
Use ITIMER_REAL for timeout handling on MacOS / Apple Silicon system
setitimer(ITIMER_PROF) fires too early on MacOS 14 when running on Apple
Silicon. See https://openradar.appspot.com/radar?id=5583058442911744.

Fixes GH-12814
Closes GH-13567
2024-05-28 15:25:46 +02:00
Pierrick Charron
c69c84a5f6
PHP-8.2 is now for PHP 8.2.21-dev 2024-05-21 14:32:07 -04:00
Dmitry Stogov
7a9e0fb39b
Fix incorrect inheritance of private trait methods (#14163)
The bug was introduced in c6b75f9328
2024-05-07 13:16:23 +03:00
Dmitry Stogov
c6b75f9328
Fix prototype for trait methods (#14148)
* Fix prototype for trait methods

Fixes GH-14009

* Clenup do_inheritance_check_on_method()

Remove wierd checks and define the behavior by explicit set of flags

* Fix naming and indentation

---------

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2024-05-06 21:39:30 +03:00
Ilija Tovilo
f8d1864bbb
Delay #[Attribute] arg validation until runtime
Fixes GH-13970
Closes GH-14105

We cannot validate at compile-time for multiple reasons:

* Evaluating the argument naively with zend_get_attribute_value can lead to code
  execution at compile time through the new expression, leading to possible
  reentrance of the compiler.
* Even if the evaluation was possible, it would need to be restricted to the
  current file, because constant values coming from other files can change
  without affecting the current compilation unit. For this reason, validation
  would need to be repeated at runtime anyway.
* Enums cannot be instantiated at compile-time (the actual bug report). This
  could be allowed here, because the value is immediately destroyed. But given
  the other issues, this won't be needed.

Instead, we just move it to runtime entirely. It's only needed for
ReflectionAttribute::newInstance(), which is not particularly a hot path. The
checks are also simple.
2024-05-06 12:38:56 +02:00
Ilija Tovilo
d670e131df
Fix __SANITIZE_ADDRESS__ redeclaration warning 2024-04-29 16:13:49 +02:00
Sergey Panteleev
3b5321dffe
PHP-8.2 is now for PHP 8.2.20-dev 2024-04-23 17:22:54 +03:00
SATO Kentaro
f8b9030b4e
Temporary reset filename and lineno override before autoload
Closes GH-10232
Closes GH-13313
2024-04-22 10:56:45 +02:00
Ilija Tovilo
b3e26c3036
Fix missing handling of CALLABLE_CONVERT in cleanup_unfinished_calls()
Fixes GH-14003
2024-04-19 20:04:51 +02:00
Ilija Tovilo
1acd7a0919
Add missing COMPILE_IGNORE_OTHER_FILES check for static calls
Closes GH-13986
2024-04-17 22:39:05 +02:00
Kévin Dunglas
f6e8145b47
fix: zend-max-execution-timers with negative or high timeout value (#13942)
Align the behavior of zend-max-execution-timers with other timeout impls: Negative or very high timeout values are equivalent to no timeout
2024-04-16 14:13:36 +02:00
Niels Dossche
c3acfb1b57
Fix GH-13931: Applying zero offset to null pointer in Zend/zend_opcode.c
In the test cases, the compiler bails out due to a fatal error.
The data structures used by the compiler will contain stale values.
In particular, for the test case CG(loop_var_stack) will contain data.
The next compilation will incorrectly use elements from the previous
stack.
To solve this, we reset part of the compiler data structures.
We don't do a full re-initialization via init_compiler() because that will
also reset streams and resources.

Closes GH-13938.
2024-04-15 19:39:05 +02:00
Dmitry Stogov
5f9b9c4e23
Fixed missed exception 2024-04-15 17:43:54 +02:00
Niels Dossche
ea0268264b
Fix GH-13903: ASAN false positive underflow when executing copy()
Closes GH-13917.
2024-04-08 21:03:42 +02:00
Bob Weinand
e7462bff19
Run one testsuite with observers enabled in CI (#13869)
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2024-04-02 18:11:02 +02:00
Pierrick Charron
7942268899
PHP-8.2 is now for PHP 8.2.19-dev 2024-03-26 08:49:44 -04:00
Arnaud Le Blanc
bb6b659aa8 Tests are not repeatable
gc_threshold is inherited accross requests, so the tests fail when repeating
2024-03-26 12:33:44 +01:00
Arnaud Le Blanc
c13794cdcb
Adjust GC threshold if num_roots is higher than gc_threshold after collection (#13758)
This fixes an edge case causing the GC to be triggered repeatedly.

Destructors might add potential garbage to the buffer, so it may happen that num_root it higher than gc_threshold after collection, thus triggering a GC run almost immediately. This can happen by touching enough objects in a destructor, e.g. by iterating over an array. If this happens again in the new run, and the threshold is not updated, the GC may be triggered again.

The edge case requires specific conditions to be triggered and it must happen rarely in practice:

 * At least GC_THRESHOLD_TRIGGER (100) objects must be collected during each run for the threshold to not be updated
 * At least GC_G(gc_threshold) (initially 10k) objects must be touched (decref'ed to n>0) by any destructor during each run to fill the buffer

The fix is to increase the threshold if GC_G(num_roots) >= GC_G(gc_threshold) after GC. The threshold eventually reaches a point at which the second condition is not met anymore.

The included tests trigger more than 200 GC runs before the fix, and 2 after the fix (dtors always trigger a second run).

A related issue is that zend_gc_check_root_tmpvars() may add potential garbage before the threshold is adjusted, which may trigger GC and exhaust the stack. This is fixed by setting GC_G(active)=1 around zend_gc_check_root_tmpvars().
2024-03-25 16:17:54 +01:00
Bob Weinand
059bf33e60
Properly forward the signal to the original handler if TSRM is shutdown. (#10219)
This ensures proper handling of SIGQUIT in ZTS fpm builds outside of active requests.
2024-03-18 20:24:23 +01:00
Bob Weinand
10d912d6e3
Fix GH-13712: Segmentation fault for enabled observers when calling trait method of internal trait when opcache is loaded (#13735)
Inherited methods regardless of source must share the original runtime cache. Traits were missed.
This adds ZEND_ACC_TRAIT_CLONE to internal functions as well to allow easy distinction of these.
2024-03-18 19:02:42 +01:00
David Carlier
868257a3de Fix GH-13727: macro generating invalid call test prototypes fixes.
autoconf/libtool generating code to test features missed `void` for
C calls prototypes w/o arguments.
Note that specific changes related to libtool have to be upstreamed.

Co-authored-by: Peter Kokot <petk@php.net>

close GH-13732
2024-03-18 06:53:39 +00:00
Niels Dossche
39b8d5c871 Fix GH-13612: Corrupted memory in destructor with weak references
Inside `zend_object_std_dtor` the weakrefs are notified after the destruction
of properties already took place. In this test case, the destructor of an anon
class will be invoked due to the property destruction. That class has a
weak reference to its parent. This means that the destructor can access
parent properties that already have been destroyed, resulting in a UAF.
Fix this by notifying the weakrefs at the start of the object's
destruction.

Closes GH-13613.
2024-03-08 18:26:17 +01:00
Sergey Panteleev
e1a8ebd61b
PHP-8.2 is now for PHP 8.2.18-dev 2024-02-27 17:26:44 +03:00
Niels Dossche
2f605820a4 Workaround ZTS persistent resource crashes (PHP 8.3 and lower)
For master (8.4-dev) I merged GH-13381. But that PR changes public API
of TSRM, so cannot be used on lower branches.

This patch is a safe workaround for the issue, in combination with a
pre-existing fix using `ifdef ZTS + if (module_started)` inside pgsql
and odbc. The idea is to delay unloading modules until the persistent
resources are destroyed. This will keep the destructor code accessible
in memory.

This is not a proper fix on its own, because we still need the
workaround of not accessing globals after module destruction.
The proper fix is in master.

Closes GH-13388.
2024-02-20 21:24:43 +01:00
Pierrick Charron
0454f4ade4
PHP-8.2 is now for PHP 8.2.17-dev 2024-01-30 12:43:37 -05:00
Dmitry Stogov
397d4c244d
Fix GH-13193: Significant performance degradation in 'foreach' starting from PHP 8.2.13 (caused by garbage collection) (#13265)
* Fix GH-13193: Significant performance degradation in 'foreach' starting from PHP 8.2.13 (caused by garbage collection)

* Don't run zend_gc_remove_root_tmpvars() if GC is not active or GC buffer is empty
2024-01-30 06:38:30 +03:00
Remi Collet
7252660941
Fix GH-13215 GCC 14 build 2024-01-22 10:58:04 +01:00