Commit Graph

130981 Commits

Author SHA1 Message Date
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
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
Ilija Tovilo
80153c9c2b
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Retire AppVeyor
2023-07-05 15:16:01 +02:00
Ilija Tovilo
f47dc259aa
Retire AppVeyor
Closes GH-11566
2023-07-05 15:14:20 +02:00
Ilija Tovilo
463e20b510
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Attempt to improve setup-slapd.sh stability
2023-07-05 15:08:22 +02:00
Ilija Tovilo
4cc800fcb4
Attempt to improve setup-slapd.sh stability
Don't restart multiple times, restart at the end where we already have a retry
loop with a small delay.

Closes GH-11590
2023-07-05 15:07:41 +02:00
Ilija Tovilo
60dd88c93e
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Use waitpid(-1) over WAIT_ANY
2023-07-04 10:29:14 +02:00
Ilija Tovilo
46e9c5104c
Use waitpid(-1) over WAIT_ANY
This macro is only available in glibc.

Closes GH-11588
2023-07-04 10:28:59 +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
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
Niels Dossche
297fec099e Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11300: license issue: restricted unicode license headers
2023-07-01 21:56:40 +02:00
Niels Dossche
ee42621ff6 Fix GH-11300: license issue: restricted unicode license headers
Closes GH-11572.
2023-07-01 21:55:21 +02:00
Anatol Belski
4e8b1ddc53 NEWS: Add note for #11298
[ci skip]

Signed-off-by: Anatol Belski <ab@php.net>
2023-07-01 18:57:46 +02:00
Anatol Belski
abc5ddb182 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  NEWS: Add note for #11298
2023-07-01 18:57:09 +02:00
Anatol Belski
928fc68c9e NEWS: Add note for #11298
[ci skip]

Signed-off-by: Anatol Belski <ab@php.net>
2023-07-01 18:56:07 +02:00
Anatol Belski
97f0d97d2a fileinfo: Backport xz detection patch
Upstream: 9b0459afab

Fixes: #11298

Signed-off-by: Anatol Belski <ab@php.net>
2023-07-01 18:02:46 +02:00
Anatol Belski
fc165ddc61 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  fileinfo: Backport xz detection fix
2023-07-01 18:00:25 +02:00
Anatol Belski
86f79b299e
fileinfo: Backport xz detection fix
Upstream: 9b0459afab

Fixes: #11298

Signed-off-by: Anatol Belski <ab@php.net>
2023-07-01 17:58:38 +02:00
Bob Weinand
cad47be8b6 Fix GH-11548 (Argument corruption when calling XMLReader::open or XMLReader::XML non-statically with observer active) 2023-06-30 15:18:37 +02:00
Ilija Tovilo
04cd8859dd
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Attempt to fix gh11498.phpt on MSAN
2023-06-30 09:42:34 +02:00
Ilija Tovilo
07dd0c80a8
Attempt to fix gh11498.phpt on MSAN
The issue might be that due to slow instrumentation the process might end before
we get to add it to the processes list. If the SIGCHLD handler executes before
adding the process to the list it will never be removed again.
2023-06-30 09:39:19 +02:00
Ilija Tovilo
838f6bffff
xfail socket zerocopy test on Cirrus + arm
Closes GH-11553
2023-06-29 08:48:48 +02:00
Ilija Tovilo
6b9d295674
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix serialization of RC1 objects appearing in object graph twice
2023-06-28 21:16:51 +02:00
Ilija Tovilo
d7d36692fd
Fix serialization of RC1 objects appearing in object graph twice
Previously, if an object had RC1 it would never be recorded in
php_serialize_data.ht because it was assumed that it could not be encountered
again. This assumption is incorrect though as the object itself may be saved
inside an array with RCn. This results in a new instance of the object, instead
of a second reference to the same object.

This is solved by tracking these objects in php_serialize_data.ht. To retain
performance, track if the current object resides in a potentially nested RCn
array. If not, and if the object is RC1 itself it may be omitted from
php_serialize_data.ht.

Additionally, we may treat the array root itself as RC1 because it may not
appear in the object graph again without recursion. Recursive arrays are still
somewhat broken even with this change, as the tracking of the array only happens
when the reference is encountered, thus resulting in a -> a' -> a' for a self
recursive array a -> a. Recursive arrays have limited support in serialize
anyway, so we ignore this case for now.

Co-authored-by: Dmitry Stogov <dmitry@zend.com>
Co-authored-by: Martin Hoch <martin@littlerobot.de>

Closes GH-11349
Closes GH-11305
2023-06-28 21:15:03 +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
Niels Dossche
ac60c5c70c Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11522: PHP version check fails with '-' separator
2023-06-27 18:29:09 +02:00
SVGAnimate
3483229199 Fix GH-11522: PHP version check fails with '-' separator
Remove php version suffix from '-' separator.

Closes GH-11524.
2023-06-27 18:28:04 +02:00
Niels Dossche
1288c07ba6 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix context option check for "overwrite" in FTP
2023-06-27 17:54:39 +02:00
Jonas
1d369a871d Fix context option check for "overwrite" in FTP
Use zend_is_true() to read value of FTP context option "overwrite".

Closes GH-11332.
2023-06-27 17:53:45 +02:00
Ilija Tovilo
7d188491c4
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix use of uninitialized memory in pcntl SIGCHLD handling
2023-06-27 11:03:42 +02:00
Ilija Tovilo
003cf9da78
Fix use of uninitialized memory in pcntl SIGCHLD handling
psig needs to stay the tail, so that we don't get a dangling element on the end.

Closes GH-11536
2023-06-27 11:02:59 +02:00
Remi Collet
b972af9589
adapt test expectation with libzip 1.10 2023-06-26 09:10:40 +02:00
Ilija Tovilo
776a685aed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [skip ci] XFAIL intl IntlCalendar::clear() test that may fail with ICU 73
2023-06-25 13:27:50 +02:00
Ilija Tovilo
8ec5a10916
[skip ci] XFAIL intl IntlCalendar::clear() test that may fail with ICU 73 2023-06-25 13:27:38 +02:00
Niels Dossche
a8bf8e37a9 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Add missing WUNTRACED
2023-06-25 11:18:15 +02:00
Niels Dossche
931d8d059b Add missing WUNTRACED
I forgot to add this in GH-11509.

Closes GH-11526.
2023-06-25 11:17:59 +02:00
Niels Dossche
022b6aa4cb Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11498: SIGCHLD is not always returned from proc_open
2023-06-23 21:58:05 +02:00
nielsdos
f39b513916 Fix GH-11498: SIGCHLD is not always returned from proc_open
Linux, and maybe other unixes, may merge multiple standard signals into
a single one. This causes issues when keeping track of process IDs.
Solve this by manually checking which children are dead using waitpid().

Test case is based on taka-oyama's test code.

Closes GH-11509.
2023-06-23 21:56:21 +02:00
nielsdos
daa891ed42 [ci skip] Add forgotten NEWS entry 2023-06-23 17:50:41 +02:00
nielsdos
b9bf9ee2cb Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix interrupted CLI output causing the process to exit
2023-06-23 17:42:45 +02:00
nielsdos
1111a9517b Fix interrupted CLI output causing the process to exit
When writing the output in the CLI is interrupted by a signal, the
writing will fail in sapi_cli_single_write(), causing an exit later in
sapi_cli_ub_write(). This was the other part of the issue in GH-11498.
The solution is to restart the write if an EINTR has been observed.

Closes GH-11510.
2023-06-23 17:39:04 +02:00
Ilija Tovilo
7f9ad4a83a
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Revert "Mangle PCRE regex cache key with JIT option"
2023-06-22 23:14:27 +02:00
Ilija Tovilo
4d91665f78
Revert "Mangle PCRE regex cache key with JIT option"
This reverts commit 466fc78d2c.
2023-06-22 23:13:37 +02:00
nielsdos
c44f79b7d5 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11492: Make test failure: ext/pdo_sqlite/tests/bug_42589.phpt
2023-06-22 20:51:11 +02:00
Vinicius Dias
039dd0b4bd Fix GH-11492: Make test failure: ext/pdo_sqlite/tests/bug_42589.phpt
Closes GH-11494.
2023-06-22 20:49:00 +02:00
Derick Rethans
1b5360587e Merge branch 'PHP-8.1' into PHP-8.2 2023-06-22 19:06:08 +01:00
Derick Rethans
812682591c Merge branch 'issue11368' into PHP-8.1 2023-06-22 19:05:59 +01:00
Derick Rethans
0747616f84 Fixed GH-11368: Date modify returns invalid datetime 2023-06-22 17:58:19 +01:00