Commit graph

506 commits

Author SHA1 Message Date
Niels Dossche
eaa2b61acb
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16604: Memory leaks in SPL constructors
2024-11-01 20:43:28 +01:00
Niels Dossche
886a5287ca
Fix GH-16604: Memory leaks in SPL constructors
Closes GH-16673.
2024-11-01 20:42:28 +01:00
Niels Dossche
88af09193d
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-14290: Member access within null pointer in extension spl
2024-05-21 23:24:15 +02:00
Niels Dossche
b3a56bd558
Fix GH-14290: Member access within null pointer in extension spl
php_pcre_replace_impl() can fail and return NULL. We should take that
error condition into account. Because other failures return false, we
return false here as well.

At first, I also thought there was a potential memory leak in the error
check of replacement_str, but found that the error condition can never
trigger, so replace that with an assertion.

Closes GH-14292.
2024-05-21 23:20:32 +02:00
Ilija Tovilo
04fd04acab
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix reference returned from CallbackFilterIterator::accept()
2023-04-20 13:43:29 +02:00
Ilija Tovilo
b2282bee32
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix reference returned from CallbackFilterIterator::accept()
2023-04-20 13:43:20 +02:00
Ilija Tovilo
5855bdcd6c
Fix reference returned from CallbackFilterIterator::accept()
Fixes oss-fuzz #58181
2023-04-20 10:18:18 +02:00
Ilija Tovilo
9d5f2f1343
Use new ZSTR_INIT_LITERAL macro (#10879) 2023-03-20 16:19:05 +01:00
Niels Dossche
2b15061fbb
Use zend_result in ext/spl where appropriate (#10734)
* Convert functions in spl_heap to return zend_result

* Convert functions in spl_iterators to return zend_result
2023-03-01 18:58:17 +01:00
Marcos Marcolin
9004725367
chore: standardize the visibility of functions. (#10708)
Co-authored-by: Marcos Marcolin <marcos@ixcsoft.com.br>
2023-02-26 14:08:33 +00:00
George Peter Banyard
32d3cae19f
Handle trampolines correctly in new FCC API + usages (#9877) 2022-11-22 17:12:53 +00:00
George Peter Banyard
8d5d3fd035 Refactor SPL Callback filter to only use FCC 2022-11-02 14:52:54 +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
George Peter Banyard
1ea1b6319e Use zend_call_function_with_return_value() in SPL iterators 2022-10-21 17:26:21 +01:00
Bob Weinand
a01dd9feda Revert "Port all internally used classes to use default_object_handlers"
This reverts commit 94ee4f9834.

The commit was a bit too late to be included in PHP 8.2 RC1. Given it's a massive ABI break, we decide to postpone the change to PHP 8.3.
2022-09-14 11:13:23 +02:00
Bob Weinand
94ee4f9834 Port all internally used classes to use default_object_handlers
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-31 16:45:27 +02:00
Máté Kocsis
b73f139c70
Declare ext/spl constants in stubs (#9226) 2022-08-02 16:37:12 +02:00
Tim Düsterhus
7ae7df5b46
RFC: Make the iterator_*() family accept all iterables (#8819)
https://wiki.php.net/rfc/iterator_xyz_accept_array
2022-07-19 16:46:32 +02:00
Christoph M. Becker
e5d9859b50
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8235: iterator_count() may run indefinitely
2022-05-03 12:59:59 +02:00
Christoph M. Becker
e004e1a93b
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-8235: iterator_count() may run indefinitely
2022-05-03 12:59:39 +02:00
Christoph M. Becker
ad7b9f4e50
Fix GH-8235: iterator_count() may run indefinitely
We need to prevent integer overflow to eventually stop the iteration.

A test case doesn't appear sensible for this, because even on 32bit
architectures a respective test easily runs for a few minutes.

Closes GH-8447.
2022-05-03 12:57:58 +02:00
George Peter Banyard
cfc38a6014
SPL: minor refactoring (#8341)
Use more appropriate types and return macros
2022-04-13 20:34:23 +01:00
Arnaud Le Blanc
72fb511d0c Stop including php_pcre.h from spl_iterators.h
This fixes GH-7774.

spl_iterators.h was including php_pcre.h so that one object intern struct could
reference a pcre_cache_entry. These object interns should not be public, so they
can be moved out of the header file.

This change moves the object interns ouf of spl_iterators.h so that php_pcre.h
doesn't need to be included from there.
2022-04-08 10:37:12 +02:00
Nikita Popov
eac65680ab Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix leak when iterating uninitialized RecursiveIteratorIterator
2021-09-24 13:18:00 +02:00
Nikita Popov
3adbafeef7 Fix leak when iterating uninitialized RecursiveIteratorIterator 2021-09-24 13:17:34 +02:00
Nikita Popov
6d505d4445 Add RETURN/RETVAL_COPY_DEREF() macros
These were missing from the set...

I think quite a few of these usages don't actually need the DEREF,
but I've just kept things as is for now.
2021-07-22 09:44:19 +02:00
Nikita Popov
c2b29308ff Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix RecursiveIteratorIterator segfault for invalid aggregate
2021-07-15 13:11:39 +02:00
Nikita Popov
b9ae73eee9 Fix RecursiveIteratorIterator segfault for invalid aggregate
The code was assuming that the returned value is an object.
Reuse the logic from IteratorIterator.
2021-07-15 13:11:28 +02:00
Nikita Popov
11f62c989e Revert "IteratorIterator::getInnerIterator() can't return null"
This reverts commit c252420d08.

This (currently) does not hold for invalid AppendIterators,
revert for now.
2021-07-15 11:01:28 +02:00
Nikita Popov
c252420d08 IteratorIterator::getInnerIterator() can't return null
If ther IteratorIterator is initialized (which we check), then
zobject cannot be undef and the return value cannot be null.
2021-07-15 10:42:34 +02:00
Nikita Popov
f7b1238f13 Handle out of order destruction of RecursiveIteratorIterator 2021-07-02 17:14:00 +02:00
Nikita Popov
c2a8934b86 Fix typo in RecursiveIteratorIterator get_gc handler 2021-07-02 16:11:48 +02:00
Patrick Allaert
aff365871a Fixed some spaces used instead of tabs 2021-06-29 11:30:26 +02:00
Nikita Popov
9c18138a71 Support GC for RecursiveIteratorIterator
And move its dtor_obj handler into free_obj, so that cycle leaks
get automatically detected.
2021-06-09 11:25:50 +02:00
Nikita Popov
0643301c75 Don't perform recursive get_gc call
On further consideration, we should be making use of the fact
that zend_object_iterator is also a zend_object here, and let
GC handle the get_gc call on it. Calling get_gc recursively like
this is generally not safe, because there is only one gc_buffer.

This also happens to be much simpler...
2021-06-09 11:15:59 +02:00
Nikita Popov
67440dd695 Null out member after releasing
Missed this when changing from zval -> zend_string.
2021-06-09 10:52:27 +02:00
Nikita Popov
b2cf198733 Use zend_string* for RecursiveTreeIterator prefixes
We don't perform any append operations on these strings, they
are fixed. Use zend_string* rather than smart_str for them.
2021-06-09 10:49:59 +02:00
Nikita Popov
6b9ffaff56 Simplify string management in RecursiveTreeIterator
Make use of zend_string rather than zval to clean up the
implementation.
2021-06-09 10:38:58 +02:00
Nikita Popov
d7eea8e1be Store cached string as zend_string
This makes the code a bit simpler.
2021-06-09 10:15:36 +02:00
Nikita Popov
88c57df53d Remove dual_it dtor, add more GC roots
Move the dual_it_free call from the dtor_obj into the free_obj
handler, allowing us to drop the dtor_obj handler entirely. This
exposes another leak in bug65387.phpt, which is addressed by
adding more GC roots in the get_gc handler.
2021-06-09 10:04:43 +02:00
Nikita Popov
15fafcd664 Expose inner dual_it iterator to GC
Moving the zend_iterator_dtor from dual_it_dtor to dual_it_free_storage
exposed this GC leak in an existing test. Forward the result of the
iterator get_gc to the dual_it get_gc.
2021-06-08 16:55:22 +02:00
Anatol Belski
56c16334e5
ext: Cleanup some dead assignments
Signed-off-by: Anatol Belski <ab@php.net>
2021-05-29 13:03:32 +02:00
George Peter Banyard
c757c61a8c
Remove unnecessary error handler replacement in SPL
Document why it is needed in the remaining cases
Drive-by refactoring

Closes GH-6955
2021-05-07 11:17:56 +01:00
KsaR
01b3fc03c3
Update http->https in license (#6945)
1. Update: http://www.php.net/license/3_01.txt to https, as there is anyway server header "Location:" to https.
2. Update few license 3.0 to 3.01 as 3.0 states "php 5.1.1, 4.1.1, and earlier".
3. In some license comments is "at through the world-wide-web" while most is without "at", so deleted.
4. fixed indentation in some files before |
2021-05-06 12:16:35 +02:00
Máté Kocsis
a92f5cbe32 Use typed property in RegexIterator 2021-04-20 14:45:42 +02:00
George Peter Banyard
5caaf40b43
Introduce pseudo-keyword ZEND_FALLTHROUGH
And use it instead of comments
2021-04-07 00:46:29 +01:00
Dmitry Stogov
16649cb60d Cache haschildren/getchildren methods of recursive iterators. 2021-03-04 17:04:55 +03:00
Máté Kocsis
4f4c031f62
Generate ext/spl class entries from stubs
Closes GH-6709
2021-02-18 13:01:51 +01:00
Nikita Popov
3e01f5afb1 Replace zend_bool uses with bool
We're starting to see a mix between uses of zend_bool and bool.
Replace all usages with the standard bool type everywhere.

Of course, zend_bool is retained as an alias.
2021-01-15 12:33:06 +01:00
Nikita Popov
2c1b5c4365 Support GC for AppendIterator
This also requires adding GC support for ArrayIterator internal
iterators.
2020-10-01 16:18:23 +02:00