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

23 Commits

Author SHA1 Message Date
Niels Dossche
3fba242124 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [ci skip] NEWS
  Fix GH-13612: Corrupted memory in destructor with weak references
2024-03-08 18:27:10 +01: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
Arnaud Le Blanc
cbf67e4fee Remove WeakMap entries whose key is only reachable through the entry value (#10932) 2023-07-16 13:39:08 +02:00
Arnaud Le Blanc
4552941219 Merge branch 'PHP-8.1'
* PHP-8.1:
  [ci skip] NEWS
  Fix `WeakMap` object reference offset causing `TypeError` (#8995)
2022-07-15 13:19:12 +02:00
Arnaud Le Blanc
aadb24e817 Merge branch 'PHP-8.0' into PHP-8.1 2022-07-15 13:15:05 +02:00
Tobias Bachert
ede92a86f2 Fix WeakMap object reference offset causing TypeError (#8995) 2022-07-15 13:00:48 +02:00
Tyson Andre
90c16dba16 Merge branch 'PHP-8.1' 2021-11-20 16:53:11 -05:00
Tyson Andre
e8283ee88b Merge branch 'PHP-8.0' into PHP-8.1 2021-11-20 16:52:50 -05:00
Tyson Andre
241bd3f454 Fix use after free when WeakMap is modified during field write
(When a value's destructor triggers a resizing or rehashing of the WeakMap)

Closes GH-7671
2021-11-20 16:52:25 -05:00
Nikita Popov
59d43a4f59 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix WeakReference uniquing is TAG_HT is used
2021-11-03 10:06:56 +01:00
Nikita Popov
66c8bf98c3 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix WeakReference uniquing is TAG_HT is used
2021-11-03 10:06:44 +01:00
Nikita Popov
546e55864d Fix WeakReference uniquing is TAG_HT is used 2021-11-03 10:06:22 +01:00
Nikita Popov
8653174539 Fix nested WeakMap destruction
This undoes the change from a4b209fdcf
and addresses the original problem by dropping the unrefs during
shutdown. All objects should get unref'ed without that, and this
code path should only get hit for dangling references due to
bailout.

Alternatively we'd have to relax some assertions that check that the
object is part of the weakrefs table, which seems worse.

Fixes oss-fuzz #40090.
2021-10-19 11:40:19 +02:00
Nikita Popov
a4b209fdcf Make weak ref notify robust against bailout
First drop it from EG(weakrefs), as the weakref_unref operation
may call a destructor, which may bail out.

Fixes oss-fuzz #39718.
2021-10-08 16:42:43 +02:00
Máté Kocsis
663536d7d9 Improve class inheritance error messages (#7307) 2021-07-27 09:42:37 +02:00
Joe Watkins
570d9b63e9 Not serializable flag permeation 2021-07-20 12:28:35 +02:00
Nikita Popov
614c0b846e Allow removing non-existing key from WeakMap
In line with usual PHP semantics. This previously triggered an
assertion failure.
2020-08-27 12:42:08 +02:00
Nikita Popov
0026d8a783 Fix use-after-free is WeakMap key and value are the same
Drop the object from the WeakMap as the last step, as this might
end up destroying the object.
2020-08-27 12:05:06 +02:00
Máté Kocsis
d30cd7d7e7 Review the usage of apostrophes in error messages
Closes GH-5590
2020-07-10 21:05:28 +02:00
Nikita Popov
653e4ea1c5 Add flag to forbid dynamic property creation on internal classes
While performing resource -> object migrations, we're adding
defensive classes that are final, non-serializable and non-clonable
(unless they are, of course). This path adds a ZEND_ACC_NO_DYNAMIC_PROPERTIES
flag, that also forbids the creation of dynamic properties on these objects.
This is a subset of #3931 and targeted at internal usage only
(though may be extended to userland at some point in the future).

It's already possible to achieve this (what the removed
WeakRef/WeakMap code does), but there's some caveats: First, this
simple approach is only possible if the class has no declared
properties, otherwise it's necessary to special-case those
properties. Second, it's easy to make it overly strict, e.g. by
forbidding isset($obj->prop) as well. And finally, it requires a
lot of boilerplate code for each class.

Closes GH-5572.
2020-06-24 11:52:36 +02:00
Nikita Popov
f8d795820e Reindent phpt files 2020-02-03 22:52:20 +01:00
Nikita Popov
d8c9902567 Implement WeakMap
RFC: https://wiki.php.net/rfc/weak_maps
2020-01-03 10:43:24 +01:00
Joe Watkins
6529d7acd9 zend_weakrefs 2019-03-12 00:35:35 +01:00