Commit Graph

222 Commits

Author SHA1 Message Date
Gina Peter Banyard
c8b45aa59a
ext/spl: Follow-up on GH-9704 (#15295)
Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>
2024-08-08 19:31:51 +01:00
Arnaud Le Blanc
11accb5cdf
Preferably include from build dir (#13516)
* Include from build dir first

This fixes out of tree builds by ensuring that configure artifacts are included
from the build dir.

Before, out of tree builds would preferably include files from the src dir, as
the include path was defined as follows (ignoring includes from ext/ and sapi/) :

    -I$(top_builddir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/main
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM
    -I$(top_builddir)/

As a result, an out of tree build would include configure artifacts such as
`main/php_config.h` from the src dir.

After this change, the include path is defined as follows:

    -I$(top_builddir)/main
    -I$(top_builddir)
    -I$(top_srcdir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM

* Fix extension include path for out of tree builds

* Include config.h with the brackets form

`#include "config.h"` searches in the directory containing the including-file
before any other include path. This can include the wrong config.h when building
out of tree and a config.h exists in the source tree.

Using `#include <config.h>` uses exclusively the include path, and gives
priority to the build dir.
2024-06-26 00:26:43 +02:00
Gina Peter Banyard
54047c1090 ext/spl: Remove some useless header includes and clarify usages 2024-06-15 01:33:09 +01:00
Gina Peter Banyard
a5cacba6d8
ext/spl: Remove spl_engine.h header (#14418)
And convert calls to spl_instantiate_arg_* to the new object_init_with_constructor() API
2024-06-08 23:46:34 +01:00
Gina Peter Banyard
fd2d869642
Clean-up some more headers (#14416)
Remove unused headers (such as php_ini.h for extensions that don't define INI settings)
Use more specific headers when possible
2024-06-08 17:15:36 +01:00
Peter Kokot
e93d23a9cb
Remove unused ext/spl SPL_API code (#13985)
The ext/spl is always enabled and building it as shared is no longer
relevant.
2024-04-19 22:50:36 +02:00
Gina Peter Banyard
0de88dfb81
ext/spl: mark all zend_object_handlers as static (#13547) 2024-02-28 15:31:28 +00:00
Niels Dossche
1d20fc5fc5 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-13531: Unable to resize SplfixedArray after being unserialized in PHP 8.2.15
2024-02-27 23:05:34 +01:00
Niels Dossche
0285395126 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-13531: Unable to resize SplfixedArray after being unserialized in PHP 8.2.15
2024-02-27 23:05:26 +01:00
Niels Dossche
8494058a1f Fix GH-13531: Unable to resize SplfixedArray after being unserialized in PHP 8.2.15
When unserializing, the cached_resize field was not reset to -1
correctly, causing the setSize() method to think we were inside of a
resize operation.

Closes GH-13543.
2024-02-27 23:04:23 +01:00
David CARLIER
9726721560
general signatures discrepencies fixes (#13122) 2024-01-10 22:19:23 +00:00
Niels Dossche
4cfc8f6d7a
Remove dead stores from ext/spl (#12550) 2023-10-29 14:42:23 +00:00
Niels Dossche
009d48da1c
Convert bounds exception in SplFixedArray to OutOfBoundsException instead of RuntimeException (#12383) 2023-10-08 18:57:57 +02:00
Niels Dossche
63a7f225ea Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix #81992: SplFixedArray::setSize() causes use-after-free
2023-08-14 21:38:36 +02:00
Niels Dossche
0b516aea25 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix #81992: SplFixedArray::setSize() causes use-after-free
2023-08-14 21:34:04 +02:00
Niels Dossche
b71c6b2c6c Fix #81992: SplFixedArray::setSize() causes use-after-free
Upon resizing, the elements are destroyed from lower index to higher
index. When an element refers to an object with a destructor, it can
refer to a lower (i.e. already destroyed) element, causing a uaf.
Set refcounted zvals to NULL after destroying them to avoid a uaf.

Closes GH-11959.
2023-08-14 21:32:22 +02:00
George Peter Banyard
d5ad75108e
More usage of known zend_str instead of C string (#11381) 2023-06-08 13:03:29 +01:00
George Peter Banyard
99fa740acb
Use common function for TypeError on illegal offset access (#10544)
This merges all usages of emitting an offset TypeError into a new ZEND_API function
zend_illegal_container_offset(const zend_string* container, const zval *offset, int type);

Where the container should represent the type on which the access is attempted (e.g. string, array)
The offset zval that is used, where the error message will display its type
The type of access, which should be a BP_VAR_* constant, to get special message for isset/empty/unset
2023-06-06 11:28:19 +01:00
Niels Dossche
930db2b2d3 Merge branch 'PHP-8.2'
* PHP-8.2:
  Handle indirect zvals and use up-to-date properties in SplFixedArray::__serialize
  [ci skip] NEWS
2023-03-30 22:07:48 +02:00
Niels Dossche
47b3fe4710 Handle indirect zvals and use up-to-date properties in SplFixedArray::__serialize
Closes GH-10925.
2023-03-30 21:43:39 +02:00
Niels Dossche
42ecd8858b Merge branch 'PHP-8.2'
* PHP-8.2:
  Revert "Handle indirect zvals in SplFixedArray::__serialize"
2023-03-27 21:54:08 +02:00
Niels Dossche
0d524eda94 Revert "Handle indirect zvals in SplFixedArray::__serialize"
This reverts commit e698938229.
2023-03-27 21:47:02 +02:00
Niels Dossche
abcb88e594 Merge branch 'PHP-8.2'
* PHP-8.2:
  Handle indirect zvals in SplFixedArray::__serialize
  Fix GH-10908: Bus error with PDO Firebird on RPI with 64 bit kernel and 32 bit userland
2023-03-27 21:21:37 +02:00
Niels Dossche
e698938229 Handle indirect zvals in SplFixedArray::__serialize
Closes GH-10925.
2023-03-27 21:02:29 +02:00
Niels Dossche
bb9480a8be Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-10907: Unable to serialize processed SplFixedArrays in PHP 8.2.4
  Fix GH-8979: Possible Memory Leak with SSL-enabled MySQL connections
2023-03-24 18:09:05 +01:00
Niels Dossche
a082696699 Fix GH-10907: Unable to serialize processed SplFixedArrays in PHP 8.2.4
The properties table can also contain numeric entries after a rebuild of
the table based on the array. Since the array can only contain numeric
entries, and the properties table can contain a mix of both, we'll add
the numeric entries from the array and only the string entries from the
properties table. To implement this we simply check if the key from the
properties table is a string.

Closes GH-10921.
2023-03-24 18:08:32 +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
Marcos Marcolin
641fe23e3a
Improve illegal offset error messages (#10504)
Co-authored-by: Marcos Marcolin <marcos@ixcsoft.com.br>
2023-02-08 12:11:41 +00:00
Tyson Andre
c4ecd82f93
Make inspecting SplFixedArray instances more memory efficient/consistent, change print_r null props handling (#9757)
* Make handling of SplFixedArray properties more consistent

Create a brand new reference counted array every time in SplFixedArray
to be freed by the callers (or return null).
Switch from overriding `get_properties` to overriding `get_properties_for` handler

* Print objects with null hash table like others in print_r

Noticed when working on subsequent commits for SplFixedArray.
Make whether zend_get_properties_for returns null or an empty array
invisible to the end user - it would be always be a non-null array for
user-defined classes.
Always print newlines with `\n\s*(\n\s*)` after objects

Noticed when working on SplFixedArray changes, e.g. in
ext/spl/tests/SplFixedArray__construct_param_null.phpt
2022-10-24 08:33:25 -04:00
Nikita Popov
1d28a7be24 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix serialization of empty SplFixedArray
2022-09-15 22:36:40 +02:00
Nikita Popov
70ad93dd6e Fix serialization of empty SplFixedArray
Avoid null pointer deref.
2022-09-15 22:36:19 +02:00
Bob Weinand
d1fc0017c9 Revert "Fix compilation on MacOS"
This reverts commit 800c6672e5.

Reverted along with a01dd9feda.
2022-09-14 11:28:06 +02:00
Bob Weinand
800c6672e5 Fix compilation on MacOS
memrchr has an always available equivalent under the name of zend_memrchr.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-31 16:45:27 +02:00
Máté Kocsis
adb45a63c0
Fix GH-9186 @strict-properties can be bypassed using unserialization (#9354)
* Emit deprecation warnings when adding dynamic properties to classes during unserialization - this will become an Error in php 9.0.
  (Adding dynamic properties in other contexts was already a deprecation warning - the use case of unserialization was overlooked)
* Throw an error when attempting to add a dynamic property to a `readonly` class when unserializing
* Add new serialization methods `__serialize`/`__unserialize` for SplFixedArray to avoid creating deprecated dynamic
  properties that would then be added to the backing fixed-size array
* Don't add named dynamic/declared properties (e.g. $obj->foo) of SplFixedArray to the backing array when unserializing
* Update tests to declare properties or to expect the deprecation warning
* Add news entry

Co-authored-by: Tyson Andre <tysonandre775@hotmail.com>
2022-08-30 07:46:32 -04:00
Ilija Tovilo
3b92a96610
Convert return type of various object handlers from int to zend_result (#8755) 2022-06-26 01:00:19 +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
Tyson Andre
b50315e73c Merge branch 'PHP-8.1'
Conflicts:
	ext/spl/tests/fixedarray_023.phpt
	ext/spl/spl_fixedarray.c (fix compile error)
2022-02-23 19:52:59 -05:00
Tyson Andre
5d907dfcee Merge branch 'PHP-8.0' into PHP-8.1 2022-02-23 19:26:24 -05:00
Tyson Andre
cd1c6f0b81
Fixes infinite recursion introduced by patch to SplFixedArray (#8105)
Closes GH-8079

Track whether the spl_fixedarray was modified since the last call to
get_properties
2022-02-23 19:23:00 -05:00
Dmitry Stogov
c77bbcd464 Fixed GH-8041 (php 8.2.0-dev crashes with assertion for cloning/get_object_vars on non-empty SplFixedArray) 2022-02-11 16:46:12 +03:00
Dmitry Stogov
a04d181578 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed GH-8044 (var_export/debug_zval_dump HT_ASSERT_RC1 debug failure for SplFixedArray)
2022-02-11 15:36:09 +03:00
Dmitry Stogov
a584d12667 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed GH-8044 (var_export/debug_zval_dump HT_ASSERT_RC1 debug failure for SplFixedArray)
2022-02-11 15:35:57 +03:00
Dmitry Stogov
52ae6417ca Fixed GH-8044 (var_export/debug_zval_dump HT_ASSERT_RC1 debug failure for SplFixedArray) 2022-02-11 15:33:31 +03:00
Tyson Andre
024d5f4b63 Cache method overrides of ArrayAccess in zend_class_entry
Previously, code such as subclasses of SplFixedArray would check for method
overrides when instantiating the objects.

This optimization was mentioned as a followup to GH-6552
2021-12-04 11:35:38 -05:00
Christoph M. Becker
9800845d43
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix #80663: Recursive SplFixedArray::setSize() may cause double-free
2021-09-28 15:55:40 +02:00
Christoph M. Becker
e73cc7aea9
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix #80663: Recursive SplFixedArray::setSize() may cause double-free
2021-09-28 15:55:11 +02:00
Christoph M. Becker
6154aa652d
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #80663: Recursive SplFixedArray::setSize() may cause double-free
2021-09-28 15:52:58 +02:00
Christoph M. Becker
2d6684091f
Fix #80663: Recursive SplFixedArray::setSize() may cause double-free
We address the `::setSize(0)` case by setting `array->element = NULL`
and `array->size = 0` before we destroy the elements.

Co-authored-by: Tyson Andre <tyson.andre@uwaterloo.ca>

Closes GH-7503.
2021-09-28 15:48:53 +02:00
Nikita Popov
4448934820 Don't mark SplFixedArray as REUSE_GET_ITERATOR
This flag only has an effect (or use) for Iterators, not for
IteratorAggregates. Removing the confusing flag.
2021-09-24 12:40:46 +02:00
Tyson Andre
27976d7dc7 Merge branch 'PHP-8.0' into PHP-8.1 2021-09-13 21:18:56 -04:00