Commit graph

494 commits

Author SHA1 Message Date
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
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
Nikita Popov
afab9eb48c Fix bug #65387
Add GC support to dual_it. This is still missing AppendIterator
support.
2020-10-01 16:12:56 +02:00
Máté Kocsis
e95fa3eb0c
Fix a few Iterator signatures
Closes GH-6176
2020-09-21 16:03:09 +02:00
George Peter Banyard
063fdd9422 Use ValueError instead of exceptions in SPL extension 2020-09-15 12:49:59 +02:00
George Peter Banyard
b6207338e8 Use normal error in SPL for uninitialized objects 2020-09-15 12:49:59 +02:00
George Peter Banyard
9affbef0e6 Use normal error in SPL for 'An iterator cannot be used with foreach by reference' 2020-09-15 12:49:59 +02:00
George Peter Banyard
61c299fe9c Error promotions in SPL
Warning to Error promotion and a Notice to Warning promotion to align
with the behaviour specified in the Reclassify Engine Warnings RFC.

Closes GH-6072
2020-09-03 19:27:02 +02:00
Nikita Popov
0a439fa932 Merge branch 'PHP-7.4'
* PHP-7.4:
  Add missing initialization check to RegexIterator::getRegex()
2020-08-14 10:42:14 +02:00
Nikita Popov
a0c231c0f5 Add missing initialization check to RegexIterator::getRegex() 2020-08-14 10:41:36 +02:00
Nikita Popov
7991fc2753 Accept zend_object in zend_read_property 2020-08-07 16:40:27 +02:00
Nikita Popov
dc30e1d812 Cleanup SPL instantiation code 2020-07-23 16:00:12 +02:00
Nikita Popov
e6ae1bf489 Check dual_it validity in CallbackFilterIterator::accept()
Avoid accessing intern->u.cbfilter null pointer, though it's
harmless here.
2020-07-22 11:31:15 +02:00
Nikita Popov
9d2af91033 Only set DIT type on successful initialization 2020-07-17 16:42:56 +02:00