Commit Graph

18853 Commits

Author SHA1 Message Date
Florian Sowade
910f579f14 Fix GH-12207 memory leak of doc blocks of static properties
When declaring the same static property with a doc block in a class and in a trait,
the doc block of the property in the class is leaked. While at it, possibly fix doc
 comment for internal classes.

Close GH-12238
2023-09-18 17:44:47 +01:00
George Peter Banyard
42010d42f1
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fixed oss-fuzz #62294: Unsetting variable after ++/-- on string variable warning
2023-09-17 15:50:54 +01:00
George Peter Banyard
0b614a6c2b
Fixed oss-fuzz #62294: Unsetting variable after ++/-- on string variable warning
Closes GH-12202
2023-09-17 15:49:46 +01:00
Tim Düsterhus
7c4db150cb
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix #[Override] on traits overriding a parent method without a matching interface (#12205)
2023-09-15 14:57:42 +02:00
Tim Düsterhus
d344fe06a2
Fix #[Override] on traits overriding a parent method without a matching interface (#12205)
Fixes GH-12189

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2023-09-15 14:57:10 +02:00
Tim Düsterhus
ede180672b
Merge branch 'PHP-8.3'
* PHP-8.3:
  Add abstract __construct() test for #[\Override] (024.phpt)
2023-09-14 12:58:31 +02:00
Tim Düsterhus
0e9d658dd2
Add abstract __construct() test for #[\Override] (024.phpt) 2023-09-14 12:58:08 +02:00
Ilija Tovilo
692cea5cbc
Use zend_error_noreturn for E_ERROR consistently
To be clear, these already don't return. zend_error_noreturn just hints at this
fact through the ZEND_NORETURN attribute.

Closes GH-12204
2023-09-14 11:44:55 +02:00
Ilija Tovilo
2227fefa17
Fix noreturn with warning that should be an error
E_WARNING does not actually abort.
2023-09-14 11:29:53 +02:00
Ben Ramsey
c1cf0026e5
PHP-8.1 is now for PHP 8.1.25-dev 2023-09-12 16:21:51 -05:00
Sergey Panteleev
5c1f746716
PHP-8.2 is now for PHP 8.2.12-dev 2023-09-12 14:53:56 +03:00
Ilija Tovilo
02d3eecf8d
Merge branch 'PHP-8.3'
* PHP-8.3:
  Improve invalid cpp modifier message
2023-09-11 16:24:16 +02:00
Ilija Tovilo
011071a3b3
Improve invalid cpp modifier message
The ZEND_MODIFIER_TARGET_CPP should really have been called _PARAM, but we
shouldn't break API at this point.

Fixes GH-12069
Closes GH-12175
2023-09-11 16:23:43 +02:00
George Peter Banyard
5c3a6eaec9
Zend: Remove dependency on zend.h for certain headers (#12166) 2023-09-11 12:27:21 +01:00
Ilija Tovilo
4217d55022
Merge branch 'PHP-8.3'
* PHP-8.3:
  [skip ci] Skip arginfo_zpp_mismatch on asan
2023-09-11 11:36:30 +02:00
Ilija Tovilo
214afe0d96
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [skip ci] Skip arginfo_zpp_mismatch on asan
2023-09-11 11:36:22 +02:00
Ilija Tovilo
1c93cdcea4
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [skip ci] Skip arginfo_zpp_mismatch on asan
2023-09-11 11:35:51 +02:00
Ilija Tovilo
5286bab392
[skip ci] Skip arginfo_zpp_mismatch on asan
These tests intermittently crash asan. It might be due to some function invoking
dl(), which is known to crash lsan. It might also be something else, the version
of asan shipped with ubuntu 22.04 is flaky.
2023-09-11 11:32:34 +02:00
Máté Kocsis
038e9b7e4b
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix #12123 Make _ZEND_TYPE_PREFIX apply only for MSVC
2023-09-10 22:43:00 +02:00
Máté Kocsis
45c7e3b06b
Fix #12123 Make _ZEND_TYPE_PREFIX apply only for MSVC
Closes GH-12136
2023-09-10 22:40:50 +02:00
David Carlier
aef5225394 zend_call_stack_get implementation for NetBSD.
Despite being OpenBSD's predecessor, the approach is in fact
a lot closer to Linux, at least in principle. We purposely
avoid reading /proc/N/maps to be more future-proof.

Close GH-11637
2023-09-09 13:48:40 +01:00
Ilija Tovilo
c803402162
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix zend_separate_if_call_and_write for FUNC_ARGs
2023-09-07 14:26:31 +02:00
Ilija Tovilo
c2bb9bc0df
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix zend_separate_if_call_and_write for FUNC_ARGs
2023-09-07 14:26:09 +02:00
Ilija Tovilo
fa9cef8b47
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix zend_separate_if_call_and_write for FUNC_ARGs
2023-09-07 14:25:43 +02:00
Ilija Tovilo
748adf18fc
Fix zend_separate_if_call_and_write for FUNC_ARGs
Fixes GH-12102
Closees GH-12140
2023-09-07 14:25:11 +02:00
Máté Kocsis
2cb4d00693
Improve detection of predefined constants
In order to include constants documented at https://www.php.net/manual/en/reserved.constants.php, as well as constants which share the same varlistentry (just like what
https://www.php.net/manual/en/class.datetimeinterface.php#datetimeinterface.constants.atom does). In the same time, special constants like
true, false, null are excluded, since the manual uses their entity (&true;, &false, &null;, respectively), and gen_stub.php couldn't detect
them.
2023-09-07 10:00:55 +02:00
George Peter Banyard
2d3bff38bb Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
2023-09-05 10:41:22 +01:00
George Peter Banyard
8a392eddf9 Fix OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
Reorder when we assign the property value to NULL which is identical to
a3a3964497

Just for the declared property case instead of dynamic.

Closes GH-12114
2023-09-05 10:40:02 +01:00
George Peter Banyard
ee6453f737 Merge branch 'PHP-8.3'
* PHP-8.3:
  Prevents double call to internal iterator rewind handler
  adds failing test case for #12060
2023-09-05 10:37:00 +01:00
George Peter Banyard
d7273c5963 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Prevents double call to internal iterator rewind handler
  adds failing test case for #12060
2023-09-05 10:36:16 +01:00
George Peter Banyard
c672a06954 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Prevents double call to internal iterator rewind handler
  adds failing test case for #12060
2023-09-05 10:27:33 +01:00
ju1ius
da7a66d647 Prevents double call to internal iterator rewind handler
Closes GH-12060

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-09-05 10:26:19 +01:00
Dmitry Stogov
8cfe2674e3 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fixed uninitialized EX(opline) access (possible Zend/tests/gh12073.phpt crash)
2023-09-05 10:13:55 +03:00
Dmitry Stogov
b4ce171aa2 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fixed uninitialized EX(opline) access (possible Zend/tests/gh12073.phpt crash)
2023-09-05 10:13:47 +03:00
Dmitry Stogov
ab6d564a7e Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed uninitialized EX(opline) access (possible Zend/tests/gh12073.phpt crash)
2023-09-05 10:13:22 +03:00
Dmitry Stogov
f1f608bf53 Fixed uninitialized EX(opline) access (possible Zend/tests/gh12073.phpt crash) 2023-09-05 10:11:54 +03:00
Ilija Tovilo
3f38105740
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix freeing of incompletely initialized closures
2023-09-04 15:40:07 +02:00
Ilija Tovilo
baf74ed1a4
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix freeing of incompletely initialized closures
2023-09-04 15:39:39 +02:00
Ilija Tovilo
6850a040f3
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix freeing of incompletely initialized closures
2023-09-04 15:39:20 +02:00
Ilija Tovilo
af2110e664
Fix freeing of incompletely initialized closures
Addref to relevant fields before allocating any memory. Also only set/remove the
ZEND_ACC_HEAP_RT_CACHE flag after allocating memory.

Fixes GH-12073
Closes GH-12074
2023-09-04 15:35:39 +02:00
Niels Dossche
e2189e5f37 Merge branch 'PHP-8.3'
* PHP-8.3:
  Tweak behaviour of dynamic properties wrt error handlers
2023-09-03 18:27:32 +02:00
Niels Dossche
eee1617f38 Tweak behaviour of dynamic properties wrt error handlers
With the fix in https://github.com/php/php-src/pull/12114, the behaviour
would change for non-dynamic properties. Align the behaviour for dynamic
properties to be the same.

Closes GH-12117.
2023-09-03 18:27:21 +02:00
George Peter Banyard
575263ff3f Merge branch 'PHP-8.3'
* PHP-8.3:
  Add tests for oss-fuzz-61469: Undef dynamic property in ++/-- unset in error handler
2023-09-02 23:35:16 +01:00
George Peter Banyard
013bb5769b Add tests for oss-fuzz-61469: Undef dynamic property in ++/-- unset in error handler
This was fixed as a consequence of a3a3964497

Closes GH-12011
2023-09-02 23:34:20 +01:00
Remi Collet
2521a3fce1
Merge branch 'PHP-8.3'
* PHP-8.3:
  ensure displays_errors is off (default)
2023-08-31 14:55:33 +02:00
Remi Collet
1f2cfd8009
ensure displays_errors is off (default) 2023-08-31 14:55:17 +02:00
George Peter Banyard
a3725f12a3 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-11876: ini_parse_quantity() accepts invalid quantities
2023-08-30 21:23:36 +01:00
George Peter Banyard
9b28e521d1 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-11876: ini_parse_quantity() accepts invalid quantities
2023-08-30 21:23:10 +01:00
George Peter Banyard
d229a480ad Fix GH-11876: ini_parse_quantity() accepts invalid quantities
Closes GH-11910
2023-08-30 21:22:13 +01:00
Pierrick Charron
ad2ac6f05f
Prepare for PHP 8.4 2023-08-29 15:25:46 -04:00
Jakub Zelenka
7deb84b7a6
Start PHP 8.4 development cycle 2023-08-29 17:19:01 +01:00
Jakub Zelenka
2eb21b0b1e
Update API versions and numbers 2023-08-29 17:04:24 +01:00
Niels Dossche
a3a3964497 Fix oss-fuzz #61712: assertion failure with error handler during binary op
Because the error handler is invoked after the property is updated,
the error handler has the opportunity to remove it before the property
is returned.

Switching the order around fixes this issue. The comments mention that
the current ordering prevents overwriting the EG(std_property_info)
field in the error handler. EG(std_property_info) no longer exists as it
was removed in 7471c217. Back then a global was used to store the
returned property info, but as this is no longer the case there is no
longer a need to protect against overwriting a global.

Closes GH-12062.
2023-08-28 20:00:49 +02:00
Bob Weinand
b07a2d4714 Address CR comments
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2023-08-28 01:25:12 +02:00
Bob Weinand
cd53ce838a Track HashTableIterators for copy-on-write copies of HashTables
When executing a foreach ($ht as &$ref), foreach calls zend_hash_iterator_pos_ex() on every iteration. If the HashTable contained in the $ht variable is not the tracked HashTable, it will reset the position to the internal array pointer of the array currently in $ht.
This behaviour is generally fine, but undesirable for copy-on-write copies of the iterated HashTable. This may trivially occur when the iterated over HashTable is assigned to some variable, then the iterated over variable modified, leading to array separation, changing the HashTable pointer in the variable. Thus foreach happily restarting iteration.
This behaviour (despite existing since PHP 7.0) is considered a bug, if not only for the behaviour being unexpected to the user, also copy-on-write should not have trivially observable side-effects by mere assignment.

The bugfix consists of duplicating HashTableIterators whenever zend_array_dup() is called (the primitive used on array separation).
When a further access to the HashPosition through the HashTableIterators API happens and the HashTable does not match the tracked one, all the duplicates (which are tracked by single linked list) are searched for the wanted HashTable. If found, the HashTableIterator is replaced by the found copy and all other copies are removed.
This ensures that we always end up tracking the correct HashTable.

Fixes GH-11244.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2023-08-28 01:25:12 +02:00
Máté Kocsis
c934e24197 Fix GH-9967 Add support for generating custom function, class const, and property attributes in stubs 2023-08-26 21:35:31 +02:00
Ilija Tovilo
5ad658bc5e Fix type macros for C++
They are now used in arginfo files.
2023-08-26 21:35:31 +02:00
David CARLIER
69f6c742d8
zend_call_stack_default_size update BSD values. (#12051) 2023-08-26 16:36:02 +01:00
ju1ius
3e0e7e3f90
releases property attributes of internal classes (#11980)
* adds test case for internal class property attribute

* releases property attributes of internal classes
2023-08-24 16:07:00 +02:00
Jakub Zelenka
53aa53f42f
Introduce Zend guard recursion protection
This PR introduces a new way of recursion protection in JSON, var_dump
and friends. It fixes issue in master for __debugInfo and also improves
perf for jsonSerializable in some cases. More info can be found in
GH-10020.

Closes GH-11812
2023-08-24 13:03:14 +01:00
Cristian Rodríguez
782ffd761b
Use a single version of strnlen (#12015)
* Zend: Make zend_strnlen available for use outside zend_compile

* exif: remove local php_strnlen, use zend_strnlen instead

* main: remove local strnlen, use zend_strnlen instead

* phar: remove local strnlen, use zend_strnlen
2023-08-22 17:40:24 +02:00
Peter Kokot
32cdd330f3
Remove unneeded zend_language_parser.h patch (#11974)
This was cleaned in 4cbffd89d9 and
patching the Zend/zend_language_parser.h file to include zend.h is not
needed anymore.
2023-08-22 11:21:42 +02:00
ju1ius
7f1c3bf09b
Adds support for DNF types in internal functions and properties (#11969)
Note that this does not add support for items generated by gen_stubs,
only for items registered dynamically via the Zend API.

Closes GH-10120
2023-08-19 00:11:06 +01:00
Ilija Tovilo
1b9ff16f92
Merge branch 'PHP-8.2'
* PHP-8.2:
  Remove redundant condition
2023-08-17 18:55:51 +02:00
Ilija Tovilo
d016c49cf5
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Remove redundant condition
2023-08-17 18:55:45 +02:00
Ilija Tovilo
dd01c74a6f
Remove redundant condition
Never refactor code just before pushing
2023-08-17 18:54:30 +02:00
Ilija Tovilo
48ede64506
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix segfault in format_default_value due to unexpected enum/object
2023-08-17 18:44:37 +02:00
Ilija Tovilo
9437aa9a8e
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix segfault in format_default_value due to unexpected enum/object
2023-08-17 18:43:49 +02:00
Ilija Tovilo
f78d1d0d10
Fix segfault in format_default_value due to unexpected enum/object
Evaluating constants at comptime can result in arrays that contain objects. This
is problematic for printing the default value of constant ASTs containing
objects, because we don't actually know what the constructor arguments were.
Avoid this by not propagating array constants.

Fixes GH-11937
Closes GH-11947
2023-08-17 18:43:11 +02:00
Pierrick Charron
4467f33e89
PHP-8.2 is now for PHP 8.2.11-dev 2023-08-15 16:08:52 -04:00
Patrick Allaert
6e3f93f2f8
PHP-8.1 is now for PHP 8.1.24-dev 2023-08-15 21:09:58 +02:00
George Peter Banyard
82972f448f Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix various bugs related to DNF types
2023-08-15 17:01:51 +01:00
George Peter Banyard
02a80c5b82 Fix various bugs related to DNF types
- GH-11958: DNF types in trait properties do not get bound properly
 - GH-11883: Memory leak in zend_type_release() for non-arena allocated DNF types
 - Internal trait bound to userland class would not be arena allocated
 - Property DNF types were not properly deep copied during lazy loading

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: ju1ius <jules.bernable@gmail.com>
2023-08-15 15:34:33 +01:00
Ilija Tovilo
ee000ea186
Fix uouv on oom on object allocation
We may OOM during object initialization. In this case, free_obj needs to guard
against NULL values. There may be more cases where this is an issue, these were
the ones I was able to discover via script.

Fixes GH-11734
2023-08-14 11:10:00 +02:00
Cristian Rodríguez
2196e2299f
Use zend_ast_size consistenly (#11955)
* opcache: use zend_ast_size helper in zend_persist_ast

* opcache: use zend_ast_size helper in zend_persist_ast_calc

* Zend: fix zend_ast_size definition

It is better not to use sizeof(struct_with_flexible_array)
and instead rely on offsetof(type, member) like most
other similar wrappers do.
2023-08-14 00:51:14 +02:00
Kamil Tekiela
f907a009f9
Align highlight_string|file with HTML standard and modern browsers
Closes GH-11913
2023-08-12 15:08:28 +01:00
Ilija Tovilo
fc9266a5fc
Move ASAN built to GitHub actions
Cirrus will no longer offer unlimited free builds starting next month. We don't
have an alternative for FreeBSD and ARM, so move what we can for now.

Closes GH-11898
2023-08-09 14:06:36 +02:00
Ilija Tovilo
db4dba6702
Move opnum_start for goto for clarification (#11911)
opnum_start denotes the start of the ZEND_FREE block of skipped consuming
opcodes. Storing the number before zend_compile_expr(..., label_ast) makes it
seem like it denotes the start of the label block. However, label_ast must only
be a zval string AST, and as such never results in an actual opcode.
2023-08-09 11:38:54 +02:00
Peter Kokot
ba35ff0893
Remove unused HAVE_GCC_GLOBAL_REGS shell variable (#11877) 2023-08-08 00:51:56 +02:00
David CARLIER
3e315df6f8 Merge branch 'PHP-8.2' 2023-08-07 19:02:55 +01:00
David CARLIER
e9e5b4c1c8 Merge branch 'PHP-8.1' into PHP-8.2 2023-08-07 19:02:44 +01:00
Kévin Dunglas
96885bc04f fix: handle the GNU specific version of strerror_r
Close GH-11882
2023-08-07 19:01:24 +01:00
Ilija Tovilo
efc73f24c3
Revert "Call cast_object handler from get_properties_for"
This reverts commit 4182813ebf.
2023-08-07 12:58:12 +02:00
Ilija Tovilo
73c5f36f5b
Assert ptr_ptr value of TMP|CONST isn't used (#11865)
We require valid code for compilation to succeed, but these paths should always
be guarded by OPx_TYPE checks and never execute. Add an assertion to verify.
2023-08-03 15:28:19 +02:00
Ilija Tovilo
120ae1719d
Add typed specialization for ZEND_COUNT (#11825) 2023-08-03 12:33:32 +02:00
Ilija Tovilo
3148da8ee1
Add block size support for tracked_malloc (#11856)
This does still deviate from USE_ZEND_ALLOC=0 in that we're not rounding up the
size of the allocation to fixed sizes. Doing so would suppress some
out-of-bounds errors checked by ASAN. Rounding up the size in
_zend_mm_block_size would not be good either as it would break code like
memset(ptr, 0 _zend_mm_block_size(ptr)).
2023-08-03 10:08:41 +02:00
Ilija Tovilo
ae431bbfeb
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix use-of-uninitialized-value in start_fake_frame
2023-08-03 09:50:32 +02:00
Ilija Tovilo
4db025bd86
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix use-of-uninitialized-value in start_fake_frame
2023-08-03 09:50:20 +02:00
Ilija Tovilo
ed27d70d9a
Fix use-of-uninitialized-value in start_fake_frame
Closes GH-11732
2023-08-03 09:49:51 +02:00
George Peter Banyard
fc3df283fb
Zend: Fix memory leak in ++/-- when overloading fetch access
Closes GH-11859
2023-08-02 18:47:08 +01:00
George Peter Banyard
2fbec0974f Fix OSS Fuzz #60734: use-after-free visible in ASAN build 2023-08-01 16:40:25 +01:00
George Peter Banyard
6ae9cf40d1 Fix OSS-fuzz #60709 unseting op via globals
It turns out not just NULL is affected nor -- but also on booleans and this also affects properties
2023-08-01 16:40:25 +01:00
Dmitry Stogov
a95316fc79 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fixed incorrect tracked malloc deallocation
2023-08-01 16:02:08 +03:00
Dmitry Stogov
5abf4f232e Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed incorrect tracked malloc deallocation
2023-08-01 16:01:57 +03:00
Dmitry Stogov
4553258df3 Fixed incorrect tracked malloc deallocation
Fixes ext/ffi/tests/list.phpt failure
2023-08-01 16:01:11 +03:00
Dmitry Stogov
79a8cf1b96 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fixed incorrect QM_ASSIGN elimination
2023-07-31 14:51:14 +03:00
Dmitry Stogov
91dc3e15e9 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed incorrect QM_ASSIGN elimination
2023-07-31 14:51:06 +03:00
Dmitry Stogov
b5f8a7270a Fixed incorrect QM_ASSIGN elimination
Fixes OSS Fuzz #60895
2023-07-31 14:50:13 +03:00
Ilija Tovilo
4182813ebf
Call cast_object handler from get_properties_for
Fixes GH-11547
Closes GH-11583
2023-07-25 17:59:44 +02:00
Ilija Tovilo
127ad70782
Fix open_basedir leak
Fixes oss-fuzz #60741
Closes GH-11780
2023-07-25 17:54:14 +02:00
Dmitry Stogov
869ecf5320 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fixed incorrect QM_ASSIGN elimination
2023-07-24 15:45:28 +03:00
Dmitry Stogov
d6a795b935 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed incorrect QM_ASSIGN elimination
2023-07-24 15:43:21 +03:00
Dmitry Stogov
9fc0eab4b4 Fixed incorrect QM_ASSIGN elimination
Fixes OSS Fuzz #60735
2023-07-24 15:42:30 +03:00
David CARLIER
2778b5d25f
zend vm savee registers support for riscv 64. (#11773)
x8 being already reserved, we can only pull x18 to x27.
2023-07-24 08:25:45 +01:00
David CARLIER
6602ddead5
zend call stack fix freebsd code path. (#11766)
The typo in HAVE_PTHREAD_ATTR_GET_STACK (might be due to pthread_attr_get_np being different from Linux's pthread_getattr_np) led to this code path never get called on FreeBSD.
2023-07-23 18:55:14 +01:00
Peter Kokot
9911ab7142
Remove unused ZEND_STACK_GROWS_DOWNWARDS constant (#11762) 2023-07-22 19:39:42 +02:00
Niels Dossche
d58e3c05c9 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-11716: cli server crashes on SIGINT when compiled with ZEND_RC_DEBUG=1
2023-07-21 15:31:33 +02:00
Niels Dossche
272dc9a09c Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11716: cli server crashes on SIGINT when compiled with ZEND_RC_DEBUG=1
2023-07-21 15:31:20 +02:00
Niels Dossche
af77d3b8da Fix GH-11716: cli server crashes on SIGINT when compiled with ZEND_RC_DEBUG=1
Closes GH-11757.
2023-07-21 15:23:56 +02:00
Peter Kokot
b132b7ab7e
Remove check for time.h and HAVE_TIME_H (#11726)
The `<time.h>` header file is part of the standard C89 headers [1] and
on current systems can be included unconditionally.

The conditional include based on Windows is there so the win32/time.h
can be included on other places when needed.

Refs:
[1] https://port70.net/~nsz/c/c89/c89-draft.html#4.1.2
[2] https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/headers.m4
2023-07-20 09:38:53 +02:00
Ilija Tovilo
b0037eda26
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix use-after-free when unregistering user stream wrapper from itself
2023-07-19 11:20:18 +02:00
Ilija Tovilo
c3ccc363c6
Fix use-after-free when unregistering user stream wrapper from itself
Fixes GH-11735
Closes GH-11737
2023-07-19 11:17:57 +02:00
Ben Ramsey
6e3c520f51
PHP-8.1 is now for PHP-8.1.23-dev 2023-07-18 16:30:49 -05:00
Máté Kocsis
c322da0606
Fix misleading pass by reference error message (#10639) 2023-07-18 15:02:38 +02:00
Ilija Tovilo
9bcdf219ec
Resolve open_basedir paths on ini update
Closes GH-10987
2023-07-18 14:43:40 +02:00
Sergey Panteleev
796a75f967
PHP-8.2 is now for PHP 8.2.10-dev 2023-07-18 14:02:43 +03:00
Máté Kocsis
d9a7f6741e Deprecate ReflectionProperty::setValue() with an incorrect 1st arg type 2023-07-18 12:59:21 +02:00
Máté Kocsis
1126232053 Deprecate calling get_class() and get_parent_class() without arguments 2023-07-18 12:59:21 +02:00
Ilija Tovilo
1057cce1c0
Always memoize calls in lhs of coalesce assignment
We don't want to invoke calls twice, even if they are considered "variables",
i.e. might be writable if returning a reference. Function calls behave the same
in all BP contexts so they don't need to be invoked twice. The singular
exception to this is nullsafe coalesce in isset/empty, because it needs to
return false/true respectively when short-circuited. However, since nullsafe
calls are not allwed in write context we may ignore this problem.

Closes GH-11592
2023-07-18 12:48:00 +02:00
Gabriel Fontes
cd9dba81c7 small fixes 2023-07-18 08:31:02 +01:00
Ilija Tovilo
a48b977d3f Use :- as ini interpolation fallback separator 2023-07-18 08:31:02 +01:00
Gabriel Fontes
bc8b9aedf6 Add fallback value syntax for ini variables 2023-07-18 08:31:02 +01:00
Ilija Tovilo
0b0cec5b8a
Fix clang warning
has_range_constraint should can be a bool, remove unused visited field.

Closes GH-11729
2023-07-18 00:49:13 +02:00
Ilija Tovilo
1a0ef2c1cc
Revert "Remove name field from the zend_constant struct (#10954)"
This reverts commit f42992f580.

Closes GH-11604
2023-07-17 22:32:41 +02:00
George Peter Banyard
d8696f9216
[RFC] Path to Saner Increment/Decrement operators (#10358)
* Add behavioural tests for incdec operators

* Add support to ++/-- for objects castable to _IS_NUMBER

* Add str_increment() function

* Add str_decrement() function

RFC: https://wiki.php.net/rfc/saner-inc-dec-operators

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Arnaud Le Blanc <arnaud.lb@gmail.com>
2023-07-17 15:51:24 +01:00
Ilija Tovilo
1c76da62db
Fix gc_status type info
Closes GH-11722
2023-07-17 13:49:23 +02:00
George Peter Banyard
3e2dbbf9c2 Add support for deprecating class constants 2023-07-17 05:01:13 +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
d0731934b7
Expose time spent collecting cycles in gc_status() (#11523) 2023-07-16 12:34:28 +02:00
George Peter Banyard
3d4ff5ae22
RFC: Deprecate remains of string evaluated code assertions (#11671)
Link: https://wiki.php.net/rfc/assert-string-eval-cleanup
2023-07-13 15:45:32 +01:00
David CARLIER
a077c2dd6c Merge branch 'PHP-8.2' 2023-07-13 12:40:59 +01:00
David CARLIER
0309800b4d Merge branch 'PHP-8.1' into PHP-8.2 2023-07-13 12:40:47 +01:00
David Carlier
69b4360e88 zend_gdb disable gdb detection for FreeBSD < 11.
ref PR: https://github.com/php/php-src/pull/11599.

Close GH-11646
2023-07-13 12:39:58 +01:00
Ilija Tovilo
d9db446065
Fix iface const visibility variance check 2023-07-13 10:52:58 +02:00
Ilija Tovilo
7343ae5d3c
Fix missing iface class const inheritance type check 2023-07-13 10:40:19 +02:00
Ilija Tovilo
c1a7058e66
Merge branch 'PHP-8.2'
* PHP-8.2:
  Always memoize assert
2023-07-12 16:36:14 +02:00
Ilija Tovilo
6d98c085a1
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Always memoize assert
2023-07-12 16:36:08 +02:00
Ilija Tovilo
b1b7c61a27
Always memoize assert
Closes GH-11686
2023-07-12 16:35:09 +02:00
Ilija Tovilo
a833937725
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix double-compilation of arrow-function
2023-07-12 11:01:38 +02:00
Ilija Tovilo
060df83a98
Fix double-compilation of arrow-function
We transform the arrow function by nesting the expression into a return
statement. If we compile the arrow function twice this would be done twice,
leading to a compile assertion.

Fix oss-fuzz #60411
Closes GH-11632
2023-07-12 11:01:23 +02:00
Niels Dossche
3d944a367e Update type inference for ZEND_STRLEN
Since PHP 8.0, this cannot return NULL anymore, the only possible return
value is long. See https://wiki.php.net/rfc/consistent_type_errors.
2023-07-10 11:04:00 +02:00
Niels Dossche
838d80e7ee Update type inference for ZEND_GET_CLASS and ZEND_GET_CALLED_CLASS
These cannot return false anymore since PHP 8.0.
2023-07-10 11:03:43 +02:00
David Carlier
343b599747 zend call stack, follow-up on 75e9980.
user stack usable implementation for openbsd.

Close GH-11626
2023-07-08 15:32:57 +01:00
David CARLIER
75e9980054
zend stack: prepare zend_call_stack_get implementation for OpenBSD. (#11578) 2023-07-07 18:03:07 +01:00
Niels Dossche
0b2e6bc2b0 Cache d_type in directory entry 2023-07-07 18:02:32 +02:00
Arnaud Le Blanc
72a163aa90
Add stack limit check in zend_eval_const_expr() (#11424) 2023-07-07 14:18:15 +02:00
Ilija Tovilo
11aee73572
Fix incorrect handling of unwind and graceful exit exceptions
These exceptions should not invoke the user error handler, and not cause bailing
of the request.

Fixes GH-11601
Closes GH-11608
2023-07-07 08:15:17 +02:00
Ilija Tovilo
dbbcbcb5b5
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix use-of-uninitialized-value with ??= on assert
2023-07-06 09:39:46 +02:00
Ilija Tovilo
ac3ff5bb7a
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix use-of-uninitialized-value with ??= on assert
2023-07-06 09:39:05 +02:00
Ilija Tovilo
84a2e48050
Fix use-of-uninitialized-value with ??= on assert
Normally, PHP evaluates all expressions in offsets (property or array), as well
as the right hand side of assignments before actually fetching the offsets. This
is well explained in this blog post.

https://www.npopov.com/2017/04/14/PHP-7-Virtual-machine.html#writes-and-memory-safety

For ??= we have a bit of a problem in that the rhs must only be evaluated if the
lhs is null or undefined. Thus, we have to first compile the lhs with BP_VAR_IS,
conditionally run the rhs and then re-fetch the lhs with BP_VAR_W to to make
sure the offsets are valid if they have been invalidated.

However, we don't want to just re-evaluate the entire lhs because it may contain
side-effects, as in $array[$x++] ??= 42;. In this case, we don't want to
re-evaluate $x++ because it would result in writing to a different offset than
was previously tested. The same goes for function calls, like
$array[foo()] ??= 42;, where the second call to foo() might result in a
different value. PHP behaves correctly in these cases. This is implemented by
memoizing sub-expressions in the lhs of ??= and reusing them when compiling the
lhs for the second time. This is done for any expression that isn't a variable,
i.e. anything that can (potentially) be written to.

Unfortunately, this also means that function calls are considered writable due
to their return-by-reference semantics, and will thus not be memoized. The
expression foo()['bar'] ??= 42; will invoke foo() twice. Even worse,
foo(bar()) ??= 42; will call both foo() and bar() twice, but
foo(bar() + 1) ??= 42; will only call foo() twice. This is likely not by design,
and was just overlooked in the implementation. The RFC does not specify how
function calls in the lhs of the coalesce assignment behaves. This should
probably be improved in the future.

Now, the problem this commit actually fixes is that ??= may memoize expressions
inside assert() function calls that may not actually execute. This is not only
an issue when using the VAR in the second expression (which would usually also
be skipped) but also when freeing the VAR. For this reason, it is not safe to
memoize assert() sub-expressions.

There are two possible solutions:

1. Don't memoize any sub-expressions of assert(), meaning they will execute
   twice.
2. Throw a compile error.

Option 2 is not quite simple, because we can't disallow all memoization inside
assert(), as that would break assertions like assert($array[foo()] ??= 'bar');.
Code like this is highly unlikely (and dubious) but possible. In this case, we
would need to make sure that a memoized value could not be used across the
assert boundary it was created in. The complexity for this is not worthwhile. So
we opt for option 1 and disable memoization immediately inside assert().

Fixes GH-11580
Closes GH-11581
2023-07-06 09:38:41 +02:00
Ilija Tovilo
80873d28b1
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix trailing if element JMP lineno
2023-07-05 21:04:45 +02:00
Ilija Tovilo
a5e89c5686
Fix trailing if element JMP lineno
Having this lineno on the same last compiled element can lead to an incorrectly
covered line number.

if (true) {
    if (false) {
        echo 'Never executed';
    }
} else {
}

The echo will be reported as covered because the JMP from the if (true) branch
to the end of the else branch has the same lineno as the echo.

This is lacking a test because zend_dump.c does not have access to
ctx->debug_level and I don't think it's worth adjusting all the cases.

Closes GH-11598
2023-07-05 21:04:11 +02:00
George Peter Banyard
a342138e17
Revert "Use binary safe case compare in new zend_string API"
This reverts commit eb5cc1372c.

A) I'm using the function incorectly
B) Somehow the function is undefined although it's used in other zend_string APIs
2023-07-05 18:13:04 +01:00
George Peter Banyard
eb5cc1372c
Use binary safe case compare in new zend_string API 2023-07-05 18:04:45 +01:00
Ilija Tovilo
ad1b70d67e
Revert "Revert "Remove name field from the zend_constant struct (#10954)""
This reverts commit 9f4bd3040d.
2023-07-04 16:42:40 +02:00
Ilija Tovilo
7b355e8d34
Revert "Merge branch 'PHP-8.2'"
This reverts commit 45a3f178dc, reversing
changes made to b2a54bc6af.
2023-07-04 09:18:49 +02:00
Ilija Tovilo
ef4f08832c
Revert "Fix GH-9967 Add support for generating custom function, class const, and property attributes in stubs"
This reverts commit d7ab0ff0c8.
2023-07-04 09:11:14 +02:00
Máté Kocsis
9f4bd3040d
Revert "Remove name field from the zend_constant struct (#10954)"
This reverts commit f42992f580.

Fix GH-11423
2023-07-03 15:16:24 +02:00
Máté Kocsis
45a3f178dc
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-9967 Add support for generating custom function, class const, and property attributes in stubs

Closes GH-10170
2023-07-03 11:17:08 +02:00
Máté Kocsis
d7ab0ff0c8
Fix GH-9967 Add support for generating custom function, class const, and property attributes in stubs 2023-07-03 08:32:58 +02:00
Máté Kocsis
3906bccc00 Add support for typed class constants in stubs 2023-07-01 11:50:04 +02:00
Tim Düsterhus
49ef6e209d
RFC: Add #[Override] attribute (#9836)
* Add #[Override] attribute

* Move #[\Override] tests into Zend/tests/attributes/override/

* Check `check_only` before removing `ZEND_ACC_OVERRIDE`

* NEWS/UPGRADING for #[\Override]
2023-06-29 20:23:53 +02:00
Ilija Tovilo
ee4ebab5a9
[skip ci] Improve inheritance checked comment
zend_can_early_bind() might have already detected that the methods are
incompatible. In that case the class is still early bound, but must compile
error when inheritance is performed. Thus it is only safe to skip compatibility
checks when zend_can_early_bind() has succeeded.
2023-06-29 09:35:42 +02:00
Ilija Tovilo
5723fa2275
[skip ci] Document do_inheritance_check_on_method_ex() check_only and check params
These are quite confusingly named.
2023-06-29 09:18:59 +02:00
Ilija Tovilo
68ef3938f4
Fix missing "Optional parameter before required" deprecation on union null type
The check would only work for the ?type syntax, but not  type|null. Switch to a
check during type compilation instead.

Fixes GH-11488
Closes GH-11497
2023-06-28 20:45:43 +02:00
Ilija Tovilo
a94216dcb7
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix mis-compilation of by-reference nullsafe operator
2023-06-28 20:37:25 +02:00
Ilija Tovilo
54dfa86728
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix mis-compilation of by-reference nullsafe operator
2023-06-28 20:36:30 +02:00
Ilija Tovilo
dc73b73f8b
Fix mis-compilation of by-reference nullsafe operator
Fixes oss-fuzz #60011
Closes GH-11540

Co-authored-by: Dmitry Stogov <dmitry@zend.com>
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2023-06-28 20:35:29 +02:00
nielsdos
3c872661c1 Fix GH-11507: String concatenation performance regression in 8.3
When the code was moved to solve the uaf for memory overflow, this
caused the refcount to be higher than one in some self-concatenation
scenarios. This in turn causes quadratic time performance problems when
these concatenations happen in a loop.

Closes GH-11508.
2023-06-22 23:42:25 +02:00
Patrick Allaert
973e9b2eec
Fixes "GC_BENCH" is not defined in extensions including zend_gc.h
Compilation warning encountered:

include/php/Zend/zend_gc.h:49:5: warning: "GC_BENCH" is not defined, evaluates to 0 [-Wundef]
   49 | #if GC_BENCH
      |     ^~~~~~~~
2023-06-22 17:40:15 +02:00
Ilija Tovilo
fae42c8bd8
Fix assertion violation for invalid class const objects in const expressions (#11458)
Fixes oss-fuzz #59764
2023-06-21 14:59:05 +02:00
Sergey Panteleev
884a53f39a
PHP-8.2 is now for PHP 8.2.9-dev 2023-06-20 17:25:30 +03:00
Patrick Allaert
6c4b1e0417
PHP-8.1 is now for PHP 8.1.22-dev 2023-06-20 16:07:05 +02:00
George Peter Banyard
ea8f934fe5
Zend: Expose zendi_try_get_long() function via a public API (#10175) 2023-06-19 14:07:46 +01:00
George Peter Banyard
80e90ad7ba
Add number or str ZPP macros 2023-06-18 13:09:03 +01:00
Ilija Tovilo
b3e33be443
Forward shutdown exceptions to user error handlers
Fixes GH-10695
Closes GH-110905
2023-06-15 17:11:22 +02:00
Niels Dossche
5c789806ef Fix GH-11406: segfault with unpacking and magic method closure
The magic method trampoline closure may be variadic. However, the
arg_info for the variadic argument was not set, resulting in a crash
both in reflection and in the VM.

Fix it by creating an arg_info containing a single element in case of
the variadic case. The variadic argument is the last one (and in this
case only one) in the arg_info array.

We make sure the argument info is equivalent to the argument info of
`$closure` of the following code snippet:
```
function foo(...$arguments) {}
$closure = foo(...);
```

Closes GH-11417.
2023-06-13 17:39:47 +02:00
Bob Weinand
95e6ce6ede Merge branch 'PHP-8.2' 2023-06-09 14:01:44 +02:00
Bob Weinand
709540ccdc Fix add/remove observer API with multiple observers installed
Depending on the order in which observers were installed, some observers might have been executed twice after removal of another observer. Also, adding an observer could produce a bogus pointer.
2023-06-09 14:00:53 +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
Dmitry Stogov
962a777a37 Merge branch 'PHP-8.2'
* PHP-8.2:
  Keep consistent EG(current_execute_data) after return from generator (#11380)
2023-06-08 14:55:56 +03:00
Dmitry Stogov
42619b2378 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Keep consistent EG(current_execute_data) after return from generator (#11380)
2023-06-08 14:55:43 +03:00
Dmitry Stogov
06d68738b7
Keep consistent EG(current_execute_data) after return from generator (#11380) 2023-06-08 14:55:18 +03:00
Niels Dossche
79d024ac0e
Allow final modifier when using a method from a trait (#11394)
Fixes GH-11388.

Following https://wiki.php.net/rfc/horizontalreuse which introduced traits,
this should be allowed.
The implementation was refactored in 3f8c729. That commit is the first time
the "final" check appears AFAICT, but no reason was given for why. That
commit seems to have landed in 5.4.11 and the NEWS for that version doesn't
seem to mention something relevant to the behaviour change.
This patch removes the restriction of the final modifier.

Closes GH-11394.
2023-06-07 23:53:21 +02:00
Florian Engelhardt
bde6f2a2f7
Fix initial array size in gc_status() (#11393)
Small fix for the initial array size to reflect the number of items that will be added.
2023-06-07 23:51:18 +02: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
61e1f8aaeb Let closure created from magic method accept named parameters
Implements GH-11348.

Closes GH-11364.
2023-06-05 20:03:09 +02:00
George Peter Banyard
9ce6980b4d
Use known zend_string pointer to check for equality instead of C strings (#11370)
* Compare __invoke magic method name with known zend_string pointer

* Compare __sleep/__wakeup magic method name with known zend_string pointer
2023-06-05 13:59:04 +01:00
George Peter Banyard
ce724d186d Assert zend_constant exist
If not the enum case does not exist and it is a programming error
2023-06-02 20:33:20 +01:00
George Peter Banyard
c5d7264149 Fix file descriptor check
Technically 0 is a valid file descriptor
2023-06-02 20:33:20 +01:00
Kirill Nesmeyanov
b495a916a4
Add string output escaping into zend dump (phpdbg + opcache debug) (#11337)
* Add string output escaping into zend dump (phpdbg + opcache debug)

* Use ZSTR_VAL macro instead direct string access

* Move "escaped_string" into local switch/case scope

* Add zend_string_release

* Add Z_STR_P macro instead direct string access

* Merge zend_string declaration and its assigment in one stmt
2023-05-29 16:45:00 +03:00
Ilija Tovilo
fbe6696d49 Revert "Use zend_ast_apply in zend_eval_const_expr (#11261)"
This reverts commit 1c733c8bbc.

Fixes GH-11320
2023-05-26 12:15:01 +02:00
Ilija Tovilo
8ed66b4347 Add tests for list() in assignment in array literals
Array literals will constant evaluate their elements. These can include
assignments, even though these are not valid constant expressions. The lhs of
assignments can be a list() element (or []) which is parsed as an array with a
special flag.
2023-05-26 12:15:01 +02:00
Ilija Tovilo
0b1d750d91
Allow arbitrary expressions in static variable initializer
Closes GH-9301
2023-05-24 20:17:31 +02:00
Ilija Tovilo
1c733c8bbc
Use zend_ast_apply in zend_eval_const_expr (#11261)
Supporting new constant expressions requires remembering to add them to
zend_eval_const_expr, even if it only evalutes its children. This is routinely
forgotten, at least by me. Use zend_ast_apply to solve this generically.
2023-05-24 16:35:37 +02:00
Ilija Tovilo
a59c933ac0
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix exception handling in array_multisort()
2023-05-24 13:56:28 +02:00
Ilija Tovilo
0ee43718c0
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix exception handling in array_multisort()
2023-05-24 13:56:21 +02:00
Ilija Tovilo
b2ec6c24f8
Fix exception handling in array_multisort()
Closes GH-11302
2023-05-24 13:55:25 +02:00
Ilija Tovilo
ded8b7f5bd
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix access on NULL pointer in array_merge_recursive()
2023-05-24 13:37:59 +02:00
Ilija Tovilo
4676d9bc43
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix access on NULL pointer in array_merge_recursive()
2023-05-24 13:37:47 +02:00
Ilija Tovilo
f5c54fd88b
Fix access on NULL pointer in array_merge_recursive()
Closes GH-11303
2023-05-24 13:36:52 +02:00
Ben Ramsey
2f2fd06be0
PHP-8.1 is now for PHP 8.1.21-dev 2023-05-23 16:19:16 -05:00
Pierrick Charron
d5f68b50fc
PHP-8.2 is now for PHP 8.2.8-dev 2023-05-23 16:56:58 -04:00
nielsdos
24ff7eee3f Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-11245 (In some specific cases SWITCH with one default statement will cause segfault)
2023-05-23 00:36:55 +02:00
nielsdos
f6563442db Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11245 (In some specific cases SWITCH with one default statement will cause segfault)
2023-05-23 00:34:33 +02:00
Niels Dossche
5cad1a7176 Fix GH-11245 (In some specific cases SWITCH with one default statement will cause segfault)
The block optimizer pass allows the use of sources of the preceding
block if the block is a follower and not a target. This causes issues
when trying to remove FREE instructions: if the source is not in the
block of the FREE, then the FREE and source are still removed. Therefore
the other successor blocks, which must consume or FREE the temporary,
will still contain the FREE opline. This opline will now refer to a
temporary that doesn't exist anymore, which most of the time results in
a crash. For these kind of non-local scenarios, we'll let the SSA
based optimizations handle those cases.

Closes GH-11251.
2023-05-23 00:33:25 +02:00
Ilija Tovilo
7790ee8736
Fix concat_function use-after-free on out-of-memory error (#11297)
Introduced by GH-10049
2023-05-22 22:02:27 +02:00
Ilija Tovilo
5c741644d1
Fix string coercion for $a .= $a (#11296)
free_op2_string may be set to false when the operands are not strings, and
`result == op1 == op2`, by re-using the same string for both operands. In that
case, the string should still be copied to result because result is not actually
a string. Also change the op1 branch to stay consistent.

Introduced by GH-10049
2023-05-22 19:48:07 +02:00
Nikita Popov
c230aa9be3 Correctly handle multiple constants in typed declaration
While here also fix AST printing support.
2023-05-21 14:17:01 +01:00
Niels Dossche
727e26f9f2 Fix #97836 and #81705: Segfault / type confusion in concat_function
The following sequence of actions was happening which caused a null
pointer dereference:
1. debug_backtrace() returns an array
2. The concatenation to $c will transform the array to a string via
   `zval_get_string_func` for op2 and output a warning.
   Note that zval op1 is of type string due to the first do-while
   sequence.
3. The warning of an implicit "array to string conversion" triggers
   the ob_start callback to run. This code transform $c (==op1) to a long.
4. The code below the 2 do-while sequences assume that both op1 and op2
   are strings, but this is no longer the case. A dereference of the
   string will therefore result in a null pointer dereference.

The solution used here is to work with the zend_string directly instead
of with the ops.

For the tests:
Co-authored-by: changochen1@gmail.com
Co-authored-by: cmbecker69@gmx.de
Co-authored-by: yukik@risec.co.jp

Closes GH-10049.
2023-05-16 20:27:00 +02:00
Alex Dowad
97e29bed9e Use shared, immutable array for return value of mb_list_encodings
This will allow us to easily check in other mbstring functions if the
list of all supported encodings, returned by mb_list_encodings, is
passed in as input to another function.

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2023-05-16 07:01:07 -07:00
Ilija Tovilo
0600f513b3
Implement delayed early binding for classes without parents
Normally, we add classes without parents (and no interfaces or traits) directly
to the class map, early binding the class. However, if the same class has
already been registered, we would instead just add a ZEND_DECLARE_CLASS
instruction and let the handler throw a duplicate class declaration exception.

However, with opcache, if on the next request the files are included in the
opposite order, we won't perform early binding. To fix this, create a
ZEND_DECLARE_CLASS_DELAYED instruction instead and handle classes without
parents accordingly, skipping any linking for classes that are already linked in
delayed early binding.

Fixes GH-8846
2023-05-15 10:25:33 +02:00
Sara
6bd546462c
Cacheline demote to improve performance (#11101)
Once code is emitted to JIT buffer, hint the hardware to
demote the corresponding cache lines to more distant level
so other CPUs can access them more quickly.
This gets nearly 1% performance gain on our workload.

Signed-off-by: Xue,Wang   <xue1.wang@intel.com>
Signed-off-by: Tao,Su     <tao.su@intel.com>
Signed-off-by: Hu,chen    <hu1.chen@intel.com>
2023-05-15 10:28:43 +03:00
Ilija Tovilo
e0af7c332d
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix delayed early binding class redeclaration error
2023-05-12 19:29:27 +02:00
Ilija Tovilo
e3499130f1
Fix delayed early binding class redeclaration error
If we bind the class to the runtime slot even if we're not the ones who have
performed early binding we'll miss the redeclaration error in the
ZEND_DECLARE_CLASS_DELAYED handler.

Closes GH-11226
2023-05-12 19:29:04 +02:00
Ilija Tovilo
8d8cfe24d3
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix potential NULL pointer access in zend_fiber_object_gc
2023-05-11 14:35:42 +02:00
Ilija Tovilo
0a04c008d0
Fix potential NULL pointer access in zend_fiber_object_gc
Accidentally introduced in GH-11208.

Fixes oss-fuzz #58795
2023-05-11 14:33:49 +02:00
Ilija Tovilo
8f66b67ccf
Fix compilation for PHP 8.1
Accidentally introduced in 175ff603c3. arData was
not part of an anonymous union.
2023-05-10 23:59:53 +02:00
Bob Weinand
0787247b19 Merge branch 'PHP-8.2' 2023-05-10 16:46:33 +02:00
Bob Weinand
53558ffc71 Merge branch 'PHP-8.1' into PHP-8.2 2023-05-10 16:45:48 +02:00
Bob Weinand
975d28e278 Fix GH-11222: foreach by-ref may jump over keys during a rehash
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2023-05-10 16:45:05 +02:00
Ilija Tovilo
7304b56f11
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix compilation error on old GCC versions
2023-05-10 11:57:19 +02:00
Ilija Tovilo
6692477406
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix compilation error on old GCC versions
2023-05-10 11:56:07 +02:00
Amedeo Baragiola
175ff603c3
Fix compilation error on old GCC versions
In older versions of GCC (<=4.5) designated initializers would not accept member
names nested inside anonymous structures. Instead, we need to use a positional
member wrapped in {}.

Fixes GH-11063
Closes GH-11212
2023-05-10 11:55:13 +02:00
Ilija Tovilo
173680acd3
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix use-of-undefined in zend_fiber_object_gc of ex->call
2023-05-09 14:38:25 +02:00
Ilija Tovilo
06fe9ff0f1
Fix use-of-undefined in zend_fiber_object_gc of ex->call
ex->call is only set for user calls, we shouldn't access it here.
zend_unfinished_execution_gc_ex wouldn't actually use it for internal calls, so
it didn't cause any serious issues.

Closes GH-11208
2023-05-09 14:37:47 +02:00
Ilija Tovilo
5107483cd6
Correctly copy lineno for zval asts (#11203)
The comment was incorrect. Zval ASTs store their lineno in u2, but u2 does not
get copied in ZVAL_COPY. This triggers use-of-uninitialized errors with MSAN.
Unfortunately, I don't have a simple reproducer.
2023-05-07 13:17:19 +02:00
Bob Weinand
a9d11b64a7 Merge branch 'PHP-8.2' 2023-05-05 12:09:33 +02:00
Bob Weinand
cfbb47b57b Merge branch 'PHP-8.1' into PHP-8.2 2023-05-05 12:07:48 +02:00
Bob Weinand
05bd1423ee Fix GH-11189: Exceeding memory limit in zend_hash_do_resize leaves the array in an invalid state
There are more places in zend_hash.c where the resize happened after some values on the HashTable struct were set.
I reordered them all, but writing a test for these would rely on the particular amount of bytes allocated at given points in time.
2023-05-05 12:04:40 +02:00
Niels Dossche
a65cdd97a1
Implement NEON-accelerated version of BLOCKCONV for lowercasing and uppercasing strings (#11161)
Since lowercasing and uppercasing is a common operation for both
internal purposes and userland purposes, it makes sense to implement a
NEON accelerated version for this.
2023-05-04 19:51:02 +02:00
nielsdos
001e278549 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-11178: Segmentation fault in spl_array_it_get_current_data (PHP 8.1.18)
  Fix GH-11175 and GH-11177: Stream socket timeout undefined behaviour
  Fix GH-9068: Conditional jump or move depends on uninitialised value(s)
2023-05-03 19:49:02 +02:00
nielsdos
ab3f584a25 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11178: Segmentation fault in spl_array_it_get_current_data (PHP 8.1.18)
  Fix GH-11175 and GH-11177: Stream socket timeout undefined behaviour
  Fix GH-9068: Conditional jump or move depends on uninitialised value(s)
2023-05-03 19:46:51 +02:00
nielsdos
4ca8daf3ed Fix GH-9068: Conditional jump or move depends on uninitialised value(s)
This patch preserves the scratch registers of the SysV x86-64 ABI by storing
them to the stack and restoring them later. We need to do this to prevent the
registers of the caller from being corrupted. The reason these get corrupted
is because the compiler is unaware of the Valgrind replacement function and
thus makes assumptions about the original function regarding registers which
are not true for the replacement function.

For implementation I used a GCC and Clang attribute. A more general
approach would be to use inline assembly but that's also less portable
and quite hacky. This attributes is supported since GCC 7.x, but the
target option is only supported since 11.x. For Clang the target option
does not matter.

Closes GH-10221.
2023-05-03 19:39:05 +02:00
nielsdos
41cda46b70 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix too wide OR and AND range inference
2023-05-02 20:20:15 +02:00
nielsdos
e1fc246444 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix too wide OR and AND range inference
2023-05-02 20:18:05 +02:00
nielsdos
fbf5216ca0 Fix too wide OR and AND range inference
There is a typo which causes the AND and OR range inference to infer a
wider range than necessary. Fix this typo. There are many ranges for
which the inference is too wide, I just picked one for AND and one for
OR that I found through symbolic execution.

In this example test, the previous range inferred for test_or was [-27..-1]
instead of [-20..-1].
And the previous range inferred for test_and was [-32..-25]
instead of [-28..-25].

Closes GH-11170.
2023-05-02 20:08:59 +02:00
ColinHDev
e2f477c2cb
Fix negative indices on empty array not affecting next chosen index
Changed the value of nNextFreeElement in _zend_empty_array from 0 to
ZEND_LONG_MIN.

Fixes GH-11154
Closes GH-11157
2023-05-02 12:05:48 +02:00
Ilija Tovilo
e2bd92f32c
Merge branch 'PHP-8.2'
* PHP-8.2:
  Endless recursion when using + on array in foreach
2023-05-01 13:21:54 +02:00
Ilija Tovilo
50127cef92
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Endless recursion when using + on array in foreach
2023-05-01 13:21:32 +02:00
Ilija Tovilo
dc20cd9c3a
Endless recursion when using + on array in foreach
This reverts commit 84b4020eb4.

Fixes GH-11171
2023-05-01 13:20:58 +02:00
Ilija Tovilo
4f74e8672c
Merge branch 'PHP-8.2'
* PHP-8.2:
  Allow aliasing namespaces containing reserved class names
2023-04-30 13:44:58 +02:00
Ilija Tovilo
5ad6571a21
Allow aliasing namespaces containing reserved class names
This reverts commit b9f7123c5e.

Fixes GH-11152
Closes GH-11153
2023-04-30 13:44:34 +02:00
Ilija Tovilo
44724430c1
Merge branch 'PHP-8.2'
* PHP-8.2:
  Propagate STREAM_DISABLE_OPEN_BASEDIR src flag to php_stream_stat_path_ex
2023-04-30 13:37:14 +02:00
Ilija Tovilo
de9b3f648c
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Propagate STREAM_DISABLE_OPEN_BASEDIR src flag to php_stream_stat_path_ex
2023-04-30 13:37:08 +02:00
Ilija Tovilo
8bf2d587d7
Propagate STREAM_DISABLE_OPEN_BASEDIR src flag to php_stream_stat_path_ex
Otherwise we can get open_basedir warnings from the stat call while still
performing the actual copy.

Fixes GH-11138
Closes GH-11156
2023-04-30 13:36:15 +02:00
Ilija Tovilo
a00e2233e3
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix incorrect match default branch optimization
2023-04-26 15:20:35 +02:00
Ilija Tovilo
368dd81faa
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix incorrect match default branch optimization
2023-04-26 15:20:27 +02:00
Ilija Tovilo
3a76f795f8
Fix incorrect match default branch optimization
Fixes GH-11134
Closes GH-11135
2023-04-26 15:19:20 +02:00
Sergey Panteleev
8318f4a6b1
PHP-8.2 is now for PHP 8.2.7-dev 2023-04-25 18:33:13 +03:00