Commit Graph

14749 Commits

Author SHA1 Message Date
Sergey Panteleev
ad666eb6df
[ci skip] Update NEWS for c3ccc36
Fix in Streams moved from 8.2.10 to 8.2.9
2023-07-19 13:35:18 +03: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
Ilija Tovilo
e8c9c73118
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix hash_pbkdf2 options parameter
2023-07-18 19:23:10 +02:00
Ilija Tovilo
7cae6eb8db
Fix hash_pbkdf2 options parameter
The value needs to be initialized to NULL as it is optional. Furthermore, the
parameter was completely missing in the stub signature.

Closes GH-11731
2023-07-18 19:21:13 +02:00
Sergey Panteleev
796a75f967
PHP-8.2 is now for PHP 8.2.10-dev 2023-07-18 14:02:43 +03:00
Niels Dossche
8b1d352ed8 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Prevent potential deadlock if accelerated globals cannot be allocated
2023-07-17 13:00:00 +02:00
Niels Dossche
b0bc057e86 Prevent potential deadlock if accelerated globals cannot be allocated
Not sure if this is possible to hit in practice, zend_accel_error_noreturn
doesn't return so the unlock isn't called. Other callsites that use both
zend_accel_error_noreturn and zend_shared_alloc_unlock first perform the
unlocking.

Closes GH-11718.
2023-07-17 12:49:15 +02:00
George Peter Banyard
5f716bf2df
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11587 PDO::ATTR_STRINGIFY_FETCHES should return strings even in if PDO::ATTR_EMULATE_PREPARES is enabled
2023-07-17 07:09:34 +01:00
SakiTakamachi
e0aadc1c0d
Fix GH-11587 PDO::ATTR_STRINGIFY_FETCHES should return strings even in if PDO::ATTR_EMULATE_PREPARES is enabled
This also includes a fix for the MySQL ND driver to actually respect the user decided behaviour.

Closes GH-11622

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-07-17 07:08:45 +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
George Peter Banyard
1e41b0f1a5
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  ext/intl: Fix memory leak in MessageFormatter::format()
2023-07-12 15:44:41 +01:00
George Peter Banyard
536dbd74fa
ext/intl: Fix memory leak in MessageFormatter::format()
Closes GH-11658
2023-07-12 15:43:45 +01: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
832a3d193f Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10914: OPCache with Enum and Callback functions results in segmentation fault
2023-07-11 17:40:21 +02:00
Niels Dossche
bc42179133 Fix GH-10914: OPCache with Enum and Callback functions results in segmentation fault
See linked issue for analysis.

Closes GH-11675.
2023-07-11 17:38:09 +02:00
Derick Rethans
a4bdaeabf6 Fix bug GH-11600: Can't parse time strings which include (narrow) non-breaking space characters 2023-07-11 16:29:04 +01:00
Niels Dossche
2957be202e Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] NEWS
2023-07-10 16:02:31 +02:00
Niels Dossche
3d9c557041 [ci skip] NEWS 2023-07-10 16:01:52 +02:00
Niels Dossche
57ff1c354e Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11630: proc_nice_basic.phpt only works at certain nice levels
  Fix GH-11629: bug77020.phpt tries to send mail
  Fix GH-11625: DOMElement::replaceWith() doesn't replace node with DOMDocumentFragment but just deletes node or causes wrapping <></> depending on libxml2 version
2023-07-10 13:34:21 +02:00
Niels Dossche
15ff830373 Fix GH-11625: DOMElement::replaceWith() doesn't replace node with DOMDocumentFragment but just deletes node or causes wrapping <></> depending on libxml2 version
Depending on the libxml2 version, the behaviour is either to not
render the fragment correctly, or to wrap it inside <></>. Fix it by
unpacking fragments manually. This has the side effect that we need to
move the unlinking check in the replacement function to earlier because
the empty child list is now possible in non-error cases.
Also fixes a mistake in the linked list management.

Closes GH-11627.
2023-07-10 13:29:31 +02:00
Niels Dossche
3ee2ade917 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Add missing check on EVP_VerifyUpdate() in phar util
2023-07-09 22:55:01 +02:00
Niels Dossche
0d07b6d647 Add missing check on EVP_VerifyUpdate() in phar util
Closes GH-11640.
2023-07-09 22:54:27 +02:00
Niels Dossche
d0c824cb7e Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix crash when an invalid callback function is passed to CURLMOPT_PUSHFUNCTION
2023-07-08 21:39:17 +02:00
Niels Dossche
3ccd8d7866 Fix crash when an invalid callback function is passed to CURLMOPT_PUSHFUNCTION
Previously this caused a SIGABRT.

Closes GH-11639.
2023-07-08 21:32:10 +02:00
Niels Dossche
bbe72f160d [ci skip] NEWS
The alphabet is hard...
2023-07-07 19:26:58 +02:00
Niels Dossche
4a28cc725a Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-9669: phpdbg -h options doesn't list the -z option
2023-07-07 19:17:35 +02:00
Adam Saponara
119b062169 Fix GH-9669: phpdbg -h options doesn't list the -z option
Adds `-z` flag in phpdbg output.

Closes GH-9713.
2023-07-07 19:16:32 +02:00
Niels Dossche
4dcb5af3a9 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10562: Memory leak and invalid state with consecutive ftp_nb_fget
2023-07-07 17:59:00 +02:00
Niels Dossche
c962a96c34 Fix GH-10562: Memory leak and invalid state with consecutive ftp_nb_fget
When the user does not fully consume the data stream, but instead opens
a new one, a memory leak occurs. Moreover, the state is invalid: when
more commands arrive they'll be handled out-of-sync because the state of
the client does not match what the server is doing.
This leads to all sorts of weirdness, for example:
  Warning: ftp_nb_fget(): OK.

Fix it by gracefully closing the old data stream when a new data stream
is started.

Closes GH-11606.
2023-07-07 17:55:53 +02:00
Niels Dossche
ca661f2c34 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix replaced error handling in SQLite3Stmt::__construct
2023-07-07 10:27:42 +02:00
Niels Dossche
824d1f95ad Fix replaced error handling in SQLite3Stmt::__construct
The error handling is replaced using zend_replace_error_handling(), but
when SQLITE3_CHECK_INITIALIZED() returns early, the old error handling
isn't restored.

In the past, SQLITE3_CHECK_INITIALIZED() threw a warning when the check
failed. This was replaced a few years ago with an error exception. So we
can fix the bug by just removing the replacing error handling as it
accomplishes nothing anymore.

Closes GH-11607.
2023-07-07 10:24:54 +02:00
Niels Dossche
6e0f4865bd Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix most external GD 2.3.3 compatibility
2023-07-06 21:40:20 +02:00
Michael Orlitzky
0aaad46c15 Fix most external GD 2.3.3 compatibility
* ext/gd/tests/bug45799.phpt: tweak to work with external gd.

The expected output from this test contains an extra newline with
gd-2.3.3 from the system (Gentoo). Adding a whitespace wildcard takes
care of it, and the test still passes with the bundled version of gd.

* ext/gd/tests: external gd-2.3.3 compatibility.

Support for the legacy "gd" image format was removed from gd-2.3.3
upstream:
  https://github.com/libgd/libgd/blob/master/CHANGELOG.md#233---2021-09-12

Several tests for the gd extension utilize that format, and naturally
fail when gd-2.3.3 from the system is used. This commit skips those
tests when the version of gd is at least 2.3.3.

* ext/gd/tests/bug73159.phpt: skip with external gd >= 2.3.3

This test uses the imagegd2() function to check that
  https://github.com/libgd/libgd/issues/289

is fixed. When an external gd without support for the "gd" format is
used, no error is thrown, but a nonsense result is printed: this is
normal. The corresponding upstream test is disabled in that situation;
it's not expected to work.

This commit skips the corresponding PHP test under the same
circumstances to fix a test failure with external gd >= 2.3.3.

* ext/gd/tests/bug73155.phpt: skip with external gd >= 2.3.3

This test uses the imagegd2() function to check that
  https://github.com/libgd/libgd/issues/309

is fixed. When an external gd without support for the "gd" format is
used, no error is thrown, but a nonsense result is printed: this is
normal. The corresponding upstream test is disabled in that situation;
it's not expected to work.

This commit skips the corresponding PHP test under the same
circumstances to fix a test failure with external gd >= 2.3.3.

* ext/gd/tests/bug73157.phpt: skip with external gd >= 2.3.3

This test ensures that the third (chunk_size) parameter to imagegd2()
is respected when a fourth parameter is also given. However, when an
external gd without support for the "gd" format is used, the call to
imagegd2() does not really work at all. It doesn't fail, but it
produces an "image" with a nonsense chunk size.

To avoid failures when an external gd >= 2.3.3 is used, we skip the
test entirely in that case.

* ext/gd/tests/bug77973.phpt: accept lowercase "Invalid"

This test fails with an external gd because the test expects "Invalid"
where upstream gd says "invalid". This commit tweaks the expected
output to accept an arbitrary character in the i/I position.

* ext/gd/tests/bug39780_extern.phpt: update for external gd-2.3.3.

Since there are no CI runs with external gd, I can only assume that
this test has fallen out-of-date due to changes in PHP itself. I've
tweaked the expected output (only slightly) so that the test passes
with both gd-2.3.2 and gd-2.3.3.

* ext/gd/tests/bug66356.phpt: update expected output for external gd.

Newer (external) versions of GD start their error messages with
lowercase characters, whereas this test is expecting them in
uppercase. A single-character wildcard now supports both formats.

* ext/gd/tests/imagegd_truecolor.phpt: skip with external gd >= 2.3.3.

This test uses the imagegd() function, but the "gd" format has been
disabled by default in upstream gd-2.3.3. We still get some kind of
image data back from the call to imagegd(), but its "signature",
"truecolor", and "size" no longer match the expected values. This
commit skips the test when an external gd >= 2.3.3 is used.

* ext/gd/tests/createfromwbmp2_extern.phpt: update for external gd-2.3.3.
* ext/gd/tests/libgd00086_extern.phpt: update for external gd-2.3.3.

Since there are no CI runs with external gd, I can only assume that
this test has fallen out-of-date due to changes in PHP itself. I've
tweaked the expected output (only slightly) so that the test passes
with both gd-2.3.2 and gd-2.3.3.

* ext/gd/tests/bug77272.phpt: update expected output for external gd.

Newer (external) versions of GD start their error messages with
lowercase characters, whereas this test is expecting them in
uppercase. A single-character wildcard now supports both formats.

* ext/gd/tests/bug77479.phpt: update for newer external gd.

This test fails with gd-2.3.3 (at least) due to minor capitalization
and whitespace issues. We add some wildcards to account for the
difference.

Closes GH-11257.
Closes GH-11262.
Closes GH-11264.
Closes GH-11280.
2023-07-06 21:39:40 +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
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
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
928fc68c9e NEWS: Add note for #11298
[ci skip]

Signed-off-by: Anatol Belski <ab@php.net>
2023-07-01 18:56:07 +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
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
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
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
0747616f84 Fixed GH-11368: Date modify returns invalid datetime 2023-06-22 17:58:19 +01:00
Ilija Tovilo
1441f30a8d
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Remove session ID set through REQUEST_URI
2023-06-22 12:36:52 +02:00
Ilija Tovilo
f160eff441
Remove session ID set through REQUEST_URI 2023-06-22 12:35:55 +02:00
Ilija Tovilo
34a1a1bddb
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Mangle PCRE regex cache key with JIT option
2023-06-22 11:10:59 +02:00
Michael Voříšek
466fc78d2c
Mangle PCRE regex cache key with JIT option
Closes GH-11396
2023-06-22 11:08:54 +02:00
Remi Collet
f26aff1b66
[ci skip] add CVE in NEWS 2023-06-22 08:06:11 +02:00
Remi Collet
2be4d91f82
[ci skip] add CVE in NEWS 2023-06-22 08:04:56 +02:00
Remi Collet
be71cadc2f
[ci skip] add CVE in NEWS 2023-06-22 08:03:25 +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
Niels Dossche
93becab506 Fix GH-11455: Segmentation fault with custom object date properties
Closes GH-11473.
2023-06-19 19:42:09 +02:00
nielsdos
de0223113a Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Revert "Fix GH-11404: DOMDocument::savexml and friends ommit xmlns="" declaration for null namespace, creating incorrect xml representation of the DOM"
2023-06-19 19:38:30 +02:00
nielsdos
c174ebfce0 Revert "Fix GH-11404: DOMDocument::savexml and friends ommit xmlns="" declaration for null namespace, creating incorrect xml representation of the DOM"
This reverts commit 7eb3e9cd17.

Although the fix follows the spec, it causes issues because a lot of old
code assumes the incorrect behaviour PHP had since a long time.
We cannot do this yet, especially not in a stable release.
We revert this for the time being.
See GH-11428.
2023-06-19 19:37:46 +02:00
Niels Dossche
862487e95e Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix #80332: Completely broken array access functionality with DOMNamedNodeMap
2023-06-18 15:02:46 +02:00
Niels Dossche
9f7d88802e Fix #80332: Completely broken array access functionality with DOMNamedNodeMap
The problem is the usage of zval_get_long(). In particular, if the
string is non-numeric the result of zval_get_long() will be 0 without
giving an error or warning. This is misleading for users: users get the
impression that they can use strings to access the map because it
coincidentally works for the first item (which is at index 0). Of
course, this fails with any other index which causes confusion and bugs.

This patch adds proper support for using string offsets while accessing
the map. It does so by detecting if it's a non-numeric string, and then
using the getNamedItem() method instead of item(). I had to split up the
array access implementation code for DOMNodeList and DOMNamedNodeMap
first to be able to do this.

Closes GH-11468.
2023-06-18 14:59:19 +02:00
David Carlier
bc45b34b30 Merge branch 'PHP-8.1' into PHP-8.2 2023-06-18 13:45:30 +01:00
David CARLIER
f194cdf852 ext/pgsql: fix PGtrace invalid free issue.
disable trace when closing the connection, is a no op if there is no stream
attached to it.

Close GH-11403
2023-06-18 13:44:39 +01:00
Niels Dossche
bb3e5a8f55 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11404: DOMDocument::savexml and friends ommit xmlns="" declaration for null namespace, creating incorrect xml representation of the DOM
2023-06-17 13:36:44 +02:00
nielsdos
7eb3e9cd17 Fix GH-11404: DOMDocument::savexml and friends ommit xmlns="" declaration for null namespace, creating incorrect xml representation of the DOM
The NULL namespace is only correct when there is no default namespace
override. When there is, we need to manually set it to the empty string
namespace.

Closes GH-11428.
2023-06-17 13:36:00 +02:00
nielsdos
29a96e09b2 Fix GH-11451: Invalid associative array containing duplicate keys
It used the "add_new" variant which assumes the key doesn't already
exist. But in case of duplicate keys we have to take the last result.

Closes GH-11453.
2023-06-15 21:56:06 +02:00
nielsdos
923e72615f Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix bug #55294 and #47530 and #47847: namespace reconciliation issues
2023-06-15 21:50:47 +02:00
nielsdos
b30be40b86 Fix bug #55294 and #47530 and #47847: namespace reconciliation issues
We'll use the DOM wrapper version of libxml2 instead of the regular one.
It's conforming to the behaviour we expect of DOM.
Most of this patch is tests.

I based and extended the tests on the code attached with the aforementioned
bug reports. Therefore the credits for the tests:
Co-authored-by: hilse at web dot de
Co-authored-by: robin2008 at altruists dot org
Co-authored-by: sgunderson at bigfoot dot com

We'll also change the searching point of the internal reconciliation to
start at the top of the added tree to avoid redundant work now that the
function is changed.

Closes GH-11454.
2023-06-15 21:50:00 +02:00
nielsdos
a9c6b840ad Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix cross-compilation check in phar generation for FreeBSD
2023-06-13 19:13:34 +02:00
Peter
4fcb3e0d34 Fix cross-compilation check in phar generation for FreeBSD
FreeBSD's shell is very POSIX strict. This patch makes sure it works
correctly under FreeBSD too.

Closes GH-11441.
2023-06-13 19:09:58 +02:00
nielsdos
c160693515 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11433: Unable to set CURLOPT_ACCEPT_ENCODING to NULL
  Fix "invalid state error" with cloned namespace declarations
  Fix lifetime issue with getAttributeNodeNS()
2023-06-13 17:35:16 +02:00
nielsdos
a8a3b99e00 Fix GH-11433: Unable to set CURLOPT_ACCEPT_ENCODING to NULL
Closes GH-11446.
2023-06-13 17:30:57 +02:00
Niels Dossche
10d94aca4c Fix "invalid state error" with cloned namespace declarations
Closes GH-11429.
2023-06-13 17:30:18 +02:00
Niels Dossche
e309fd8461 Fix lifetime issue with getAttributeNodeNS()
It's the same issue that I fixed previously in GH-11402, but in a
different place.

Closes GH-11422.
2023-06-13 17:29:37 +02:00
Niels Dossche
2cbb0c0cc0 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix #70359 and #78577: segfaults with DOMNameSpaceNode
2023-06-09 21:41:49 +02:00
nielsdos
f2d673fb18 Fix #70359 and #78577: segfaults with DOMNameSpaceNode
* Fix type confusion and parent reference
* Manually manage the lifetime of the parent
* Add regression tests
* Break out to a helper, and apply the use-after-free fix to xpath

Closes GH-11402.
2023-06-09 21:35:55 +02:00
Jakub Zelenka
58141f062b
Merge branch 'PHP-8.1' into PHP-8.2 2023-06-09 16:38:14 +01:00
James Lucas
fd09728bb6
Fix bug GH-9356: Incomplete SAN validation of IPv6 address
IPv6 addresses are valid entries in subjectAltNames. Certificate
Authorities may issue certificates including IPv6 addresses except
if they fall within addresses in the RFC 4193 range. Google and
CloudFlare provide IPv6 addresses in their DNS over HTTPS services.

Internal CAs do not have those restrictions and can issue Unique
local addresses in certificates.

Closes GH-11145
2023-06-09 16:33:46 +01:00
Pierrick Charron
269d6c5942
Update NEWS 2023-06-06 18:10:06 -04:00
Pierrick Charron
5604f7ae22
Update NEWS 2023-06-06 18:06:13 -04:00
Pierrick Charron
b720ab99f8
Update NEWS 2023-06-06 17:59:43 -04:00
Niels Dossche
5b79c53682 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix bug #77686: Removed elements are still returned by getElementById
  Fix bug #81642: DOMChildNode::replaceWith() bug when replacing a node with itself
  Fix bug #67440: append_node of a DOMDocumentFragment does not reconcile namespaces
2023-06-04 16:27:03 +02:00
Niels Dossche
0e34ac864a Fix bug #77686: Removed elements are still returned by getElementById
From the moment an ID is created, libxml2's behaviour is to cache that element,
even if that element is not yet attached to the document. Similarly, only upon
destruction of the element the ID is actually removed by libxml2.
Since libxml2 has such behaviour deeply ingrained in the library, and uses the
cache for various purposes, it seems like a bad idea and lost cause to fight it.
Instead, we'll simply walk the tree upwards to check if the node is attached to
the document.

Closes GH-11369.
2023-06-04 16:20:34 +02:00
Niels Dossche
23f7002527 Fix bug #81642: DOMChildNode::replaceWith() bug when replacing a node with itself
Closes GH-11363.
2023-06-04 16:19:48 +02:00
Niels Dossche
b1d8e240e6 Fix bug #67440: append_node of a DOMDocumentFragment does not reconcile namespaces
The test was amended from the original issue report. For the test:
Co-authored-by: php@deep-freeze.ca

The problem is that the regular dom_reconcile_ns() only works on a
single node. We actually have to reconciliate the whole tree in case a
fragment was added. This also required to move some code around such
that this special case could be handled separately.

Closes GH-11362.
2023-06-04 16:19:04 +02:00
nielsdos
8126beac45 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11347: Memory leak when calling a static method inside an xpath query
2023-05-31 17:17:10 +02:00
nielsdos
7812772105 Fix GH-11347: Memory leak when calling a static method inside an xpath query
It's a type confusion bug. `zend_make_callable` may change the function name
of the fci to become an array, causing a crash in debug mode on
`zval_ptr_dtor_str(&fci.function_name);` in `dom_xpath_ext_function_php`.
On a production build it doesn't crash but only causes a leak, because
the array elements are not destroyed, only the array container itself
is. We can use the nogc variant because it cannot contain cycles, the
potential array can only contain 2 strings.

Closes GH-11350.
2023-05-31 17:14:57 +02:00
Ilija Tovilo
0bf8ecf9b3
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix bug GH-11246 cli/get_set_process_title
2023-05-31 17:10:17 +02:00
James Lucas
c6ae7a55b7
Fix bug GH-11246 cli/get_set_process_title
Fail to clobber_error only when the argv is a non-contiguous area
Don't increment the end_of_error if a non-contiguous area is encountered in environ

Closes GH-11247
2023-05-31 17:08:37 +02:00
nielsdos
0e7ad40900 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix DOMElement::append() and DOMElement::prepend() hierarchy checks
  Fix spec compliance error for DOMDocument::getElementsByTagNameNS
  Fix GH-11336: php still tries to unlock the shared memory ZendSem with opcache.file_cache_only=1 but it was never locked
  Fix GH-11338: SplFileInfo empty getBasename with more than one slash
2023-05-30 17:38:18 +02:00
nielsdos
b374ec399d Fix DOMElement::append() and DOMElement::prepend() hierarchy checks
We could end up in an invalid hierarchy, resulting in infinite loops and
eventual crashes if we don't check for the DOM hierarchy validity.

Closes GH-11344.
2023-05-30 17:36:26 +02:00
Niels Dossche
154c251013 Fix spec compliance error for DOMDocument::getElementsByTagNameNS
Spec link: https://dom.spec.whatwg.org/#concept-getelementsbytagnamens
Spec says we should match any namespace when '*' is provided. This was
however not the case: elements that didn't have a namespace were not
returned. This patch fixes the error by modifying the namespace check.

Closes GH-11343.
2023-05-30 17:35:38 +02:00
Niels Dossche
9c59d22a7b Fix GH-11336: php still tries to unlock the shared memory ZendSem with opcache.file_cache_only=1 but it was never locked
I chose to check for the value of lock_file instead of checking the
file_cache_only, because it is probably a little bit faster and we're
going to access the lock_file variable anyway. It's also more generic.

Closes GH-11341.
2023-05-30 17:32:02 +02:00
Niels Dossche
bce536067c Fix GH-11338: SplFileInfo empty getBasename with more than one slash
Regressed in 13e4ce386b.

Closes GH-11340.
2023-05-30 17:29:18 +02:00
Niels Dossche
dfa89879a5 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix return value in stub file for DOMNodeList::item
2023-05-29 18:50:54 +02:00
divinity76
761b9a44f8 Fix return value in stub file for DOMNodeList::item
Not explicitly documenting the possibility of returning DOMElement causes
the Intelephense linter (a popular PHP linter with ~9 million downloads:
https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client)
to think this code is bad:

  $xp->query("whatever")->item(0)->getAttribute("foo");

DOMNode does not have getAttribute (while DOMElement does).
Documenting the DOMElement return type should fix Intelephense's linter.

Closes GH-11342.
2023-05-29 18:49:26 +02:00
Niels Dossche
9ff1ea6077 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10234: Setting DOMAttr::textContent results in an empty attribute value
2023-05-29 14:12:19 +02:00
Niels Dossche
c473787abb Fix GH-10234: Setting DOMAttr::textContent results in an empty attribute value
We can't directly call xmlNodeSetContent, because it might encode the string
through xmlStringLenGetNodeList for types
XML_DOCUMENT_FRAG_NODE, XML_ELEMENT_NODE, XML_ATTRIBUTE_NODE.
In these cases we need to use a text node to avoid the encoding.
For the other cases, we *can* rely on xmlNodeSetContent because it is either
a no-op, or handles the content without encoding and clears the properties
field if needed.

The test was taken from the issue report, for the test:
Co-authored-by: ThomasWeinert <thomas@weinert.info>

Closes GH-10245.
2023-05-29 14:10:59 +02:00
David Carlier
350e449bd8 Merge branch 'PHP-8.1' into PHP-8.2 2023-05-27 16:37:48 +01:00
Daniil Gentili
1dfa277a96 Fix GCC 12 compilation on riscv64
Close GH-11321
2023-05-27 16:37:19 +01:00
nielsdos
af72727b8c Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11288 and GH-11289 and GH-11290 and GH-9142: DOMExceptions and segfaults with replaceWith
2023-05-25 23:04:49 +02:00
nielsdos
cba335d61e Fix GH-11288 and GH-11289 and GH-11290 and GH-9142: DOMExceptions and segfaults with replaceWith
This replaces the implementation of before and after with one following
the spec very strictly, instead of trying to figure out the state we're
in by looking at the pointers. Also relaxes the condition on text node
copying to prevent working on a stale node pointer.

Closes GH-11299.
2023-05-25 23:04:19 +02:00
Ilija Tovilo
5b8e941095
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Access violation when ALLOC_FALLBACK fixed
2023-05-25 11:01:58 +02:00
KoudelkaB
8946b7b141
Access violation when ALLOC_FALLBACK fixed
Close GH-11312
2023-05-25 11:01:17 +02:00
Pierrick Charron
150825d176
[skip ci] Fix release date of PHP 8.2.7 2023-05-24 23:44:32 -04:00
nielsdos
bbcf9e7107 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix allocation loop in zend_shared_alloc_startup()
2023-05-24 20:09:56 +02:00
nielsdos
6267601f84 Fix allocation loop in zend_shared_alloc_startup()
The break is outside the if, so if it succeeds or not this will always
stop after the first loop iteration instead of trying more allocators if
the first one fails.

Closes GH-11306.
2023-05-24 20:09:14 +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
7c7698f754
Fix preg_replace_callback_array() pattern validation
Closes GH-11301
2023-05-24 13:42:16 +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
caab608d57 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11281: DateTimeZone::getName() does not include seconds in offset
2023-05-23 18:56:40 +02:00
Niels Dossche
f9117eb824 Fix GH-11281: DateTimeZone::getName() does not include seconds in offset
If the seconds portion is non-zero, include the seconds in the output.

Closes GH-11282.
2023-05-23 18:52:07 +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
Niels Dossche
ffae350d11 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11099: Generating phar.php during cross-compile can't be done
2023-05-20 13:42:21 +02:00
Peter
93fa9613e1 Fix GH-11099: Generating phar.php during cross-compile can't be done
Closes GH-11243.
2023-05-20 13:35:18 +02:00
Niels Dossche
45897f592c Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11274: POST/PATCH request via file_get_contents + stream_context_create switches to GET after a HTTP 308 redirect
2023-05-19 23:43:02 +02:00
Niels Dossche
1ede3137c9 Fix GH-11274: POST/PATCH request via file_get_contents + stream_context_create switches to GET after a HTTP 308 redirect
RFC 7231 states that status code 307 should keep the POST method upon
redirect. RFC 7538 does the same for code 308. Although it's not
mandated by the RFCs that PATCH is also kept (we can choose), it seems
like keeping PATCH will be the most consistent and understandable behaviour.

This patch also changes an existing test because it was testing for the
wrong behaviour.

Closes GH-11275.
2023-05-19 23:37:20 +02:00
Ilija Tovilo
aa553af911
Fix segfault in mb_strrpos/mb_strripos with ASCII encoding and negative offset
We're setting the encoding from PHP_FUNCTION(mb_strpos), but mbfl_strpos would
discard it, setting it to mbfl_encoding_pass, making zend_memnrstr fail due to a
null-pointer exception.

Fixes GH-11217
Closes GH-11220
2023-05-15 10:36:37 +02:00
Jakub Zelenka
1129046482
Merge branch 'PHP-8.1' into PHP-8.2 2023-05-14 12:28:52 +01:00
Jakub Zelenka
4294e8d448
FPM: Fix memory leak for invalid primary script file handle
Closes GH-11088
2023-05-14 12:27:38 +01:00
Jakub Zelenka
90553af15c
Merge branch 'PHP-8.1' into PHP-8.2 2023-05-13 18:53:35 +01:00
Jakub Zelenka
5e64ead64a
Fix bug #64539: FPM status - query_string not properly JSON encoded
Closes GH-11050
2023-05-13 18:43:30 +01:00
Jakub Zelenka
bda28eb649
Merge branch 'PHP-8.1' into PHP-8.2 2023-05-13 14:14:23 +01:00
Jakub Zelenka
102953735c
Fix GH-10461: Postpone FPM child freeing in event loop
This is to prevent after free accessing of the child event that might
happen when child is killed and the message is delivered at that same
time.

Also fixes GH-10889 and properly fixes GH-8517 that was not previously
fixed correctly.
2023-05-13 14:11:42 +01:00
nielsdos
d369a7764f Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10834: exif_read_data() cannot read smaller stream wrapper chunk sizes
2023-05-12 23:40:54 +02:00
Niels Dossche
7b768485f3 Fix GH-10834: exif_read_data() cannot read smaller stream wrapper chunk sizes
php_stream_read() may return less than the requested amount of bytes by
design. This patch introduces a static function for exif which reads
from the stream in a loop until all the requested bytes are read.

For the test: Co-authored-by: dotpointer

Closes GH-10924.
2023-05-12 23:37:00 +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
ad747d93c3
[skip ci] Remove NEWS entry for reverted change in PHP 8.1 2023-05-11 11:53:18 +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
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
nielsdos
44491d17fb Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-8426: make test fail while soap extension build
2023-05-09 19:52:52 +02:00
nielsdos
6ba0b06819 Fix GH-8426: make test fail while soap extension build
If you build soap as a shared object, then these tests fail on
non-Windows, or when the PHP install hasn't been make install-ed yet,
but is executed from the development directory.

Closes GH-11211.
2023-05-09 19:48:45 +02:00
Niels Dossche
e6730565b6 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11180: hash_file() appears to be restricted to 3 arguments
2023-05-07 17:37:25 +02:00
Niels Dossche
baa07f3de3 Fix GH-11180: hash_file() appears to be restricted to 3 arguments
Closes GH-11198.
2023-05-07 17:33:28 +02:00
Niels Dossche
dc1a70c244 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11160: Few tests failed building with new libxml 2.11.0
2023-05-06 23:10:58 +02:00
Niels Dossche
7c0dfc5cf5 Fix GH-11160: Few tests failed building with new libxml 2.11.0
It's possible to categorise the failures into 2 categories:
  - Changed error message. In this case we either duplicate the test and
    modify the error message. Or if the change in error message is
    small, we use the EXPECTF matchers to make the test compatible with both
    old and new versions of libxml2.
  - Missing warnings. This is caused by a change in libxml2 where the
    parser started using SAX APIs internally [1]. In this case the
    error_type passed to php_libxml_internal_error_handler() changed from
    PHP_LIBXML_ERROR to PHP_LIBXML_CTX_WARNING because it internally
    started to use the SAX handlers instead of the generic handlers.
    However, for the SAX handlers the current input stack is empty, so
    nothing is actually printed. I fixed this by falling back to a
    regular warning without a filename & line number reference, which
    mimicks the old behaviour. Furthermore, this change now also shows
    an additional warning in a test which was previously hidden.

[1] 9a82b94a94

Closes GH-11162.
2023-05-06 23:10:07 +02:00
Niels Dossche
a0e71cb811 Fix maximum argument count of pcntl_forkx()
Closes GH-11199.
2023-05-06 20:56:27 +02:00
nielsdos
1fc18a84d9 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10031: [Stream] STREAM_NOTIFY_PROGRESS over HTTP emitted irregularly for last chunk of data
2023-05-05 19:28:01 +02:00
Niels Dossche
b33fbbfe3d Fix GH-10031: [Stream] STREAM_NOTIFY_PROGRESS over HTTP emitted irregularly for last chunk of data
It's possible that the server already sent in more data than just the headers.
Since the stream only accepts progress increments after the headers are
processed, the already read data is never added to the process.
We account for this by adjusting the progress counter by the difference of
already read header data and the body.

For the test:
Co-authored-by: aetonsi <18366087+aetonsi@users.noreply.github.com>

Closes GH-10492.
2023-05-05 19:26:44 +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
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
81e50b4ee3 Fix GH-11178: Segmentation fault in spl_array_it_get_current_data (PHP 8.1.18)
Dynamic property case in zend_get_property_info() can return NULL for
prop info. This was not handled.

Closes GH-11182.
2023-05-03 19:42:04 +02:00
nielsdos
d75c1d00a9 Fix GH-11175 and GH-11177: Stream socket timeout undefined behaviour
A negative value like -1 may overflow and cause incorrect results in the
timeout variable, which causes an immediate timeout. As this is caused
by undefined behaviour the exact behaviour depends on the compiler, its
version, and the platform.

A large overflow is also possible, if an extremely large timeout value
is passed we also set an indefinite timeout. This is because the timeout
value is at least a 64-bit number and waiting for UINT64_MAX/1000000
seconds is waiting about 584K years.

Closes GH-11183.
2023-05-03 19:40:52 +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
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
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
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
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
Máté Kocsis
a2d90aaef2
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix ZPP of pg_lo_export()
2023-04-27 18:51:19 +02:00
Máté Kocsis
f0149c5c0b
Fix ZPP of pg_lo_export()
Closes GH-11132
2023-04-27 18:50:09 +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
Patrick Allaert
725f136f9a
PHP-8.1 is now for PHP 8.1.20-dev 2023-04-25 16:18:30 +02:00
Derick Rethans
629d7740e8 Import timelib 2022.07 to address OSS fuzz issue 2023-04-21 11:29:56 +01:00
Ilija Tovilo
439919c91d
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix incorrect CG(memoize_mode) state after bailout in ??=
2023-04-20 19:46:05 +02:00
Ilija Tovilo
4c38a79f09
Fix incorrect CG(memoize_mode) state after bailout in ??=
Fixes GH-11108
Closes GH-11109
2023-04-20 19:45:02 +02:00
Derick Rethans
1dcab8a534 Add NEWS entry 2023-04-18 13:48:29 +01:00
Remi Collet
6adf2f65a1
[ci skip] NEWS for 11071 2023-04-18 11:46:18 +02:00
Remi Collet
6e8f0f53b1
[ci skip] NEWS for 11071 2023-04-18 11:45:50 +02:00
Ilija Tovilo
35c1bb2e47
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Support enums in array_unique
2023-04-16 15:35:55 +02:00
Ilija Tovilo
e8b8341d3d
Support enums in array_unique
Fixes GH-9775
Closes GH-11015
2023-04-16 15:34:56 +02:00
Niels Dossche
1799327356 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11028: Heap Buffer Overflow in zval_undefined_cv.
2023-04-15 18:30:47 +02:00
Niels Dossche
fc32d39b7f Fix GH-11028: Heap Buffer Overflow in zval_undefined_cv.
For analysis see https://github.com/php/php-src/issues/11028#issuecomment-1508460440

Closes GH-11083.
2023-04-15 18:22:55 +02:00
Niels Dossche
805f21b9bf Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] UPDATE NEWS
2023-04-11 22:18:59 +02:00
Niels Dossche
450fcc4c9b [ci skip] UPDATE NEWS
ElliotNB helped me a lot debugging this by constantly testing the
patches. It is only fair that he is mentioned too, as I couldn't have
solved it without his help.
2023-04-11 22:17:47 +02:00
Niels Dossche
9261ff7ba9 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10737: PHP 8.1.16 segfaults on line 597 of sapi/apache2handler/sapi_apache2.c
2023-04-08 16:42:52 +02:00
Niels Dossche
51faf04dbd Fix GH-10737: PHP 8.1.16 segfaults on line 597 of sapi/apache2handler/sapi_apache2.c
The TSRM keeps a hashtable mapping the thread IDs to the thread resource pointers.
It's possible that the thread disappears without us knowing, and then another thread
gets spawned some time later with the same ID as the disappeared thread.
Note that since it's a new thread the TSRM key pointer and cached pointer will be NULL.

The Apache request handler `php_handler()` will try to fetch some fields from the SAPI globals.
It uses a lazy thread resource allocation by calling `ts_resource(0);`.
This allocates a thread resource and sets up the TSRM pointers if they haven't been set up yet.

At least, that's what's supposed to happen. But since we are in a situation where the thread ID
still has the resources of the *old* thread associated in the hashtable,
the loop in `ts_resource_ex` will find that thread resource and assume the thread has been setup
already. But this is not the case since this thread is actually a new thread, just reusing the ID
of the old one, without any relation whatsoever to the old thread.
Because of this assumption, the TSRM pointers will not be setup, leading to a
NULL pointer dereference when trying to access the SAPI globals.

We can easily detect this scenario: if we're in the fallback path, and the pointer is NULL,
and we're looking for our own thread resource, we know we're actually reusing a thread ID.
In that case, we'll free up the old thread resources gracefully (gracefully because
there might still be resources open like database connection which need to be
shut down cleanly). After freeing the resources, we'll create the new resources for
this thread as if the stale resources never existed in the first place.
From that point forward, it is as if that situation never occurred.
The fact that this situation happens isn't that bad because a child process containing
threads will eventually be respawned anyway by the SAPI, so the stale thread resources
won't remain forever.

Note that we can't simply assign our own TSRM pointers to the existing
thread resource for our ID, since it was actually from a different thread
(just with the same ID!). Furthermore, the dynamically loaded extensions
have their own pointer, which is only set when their constructor is
called, so we'd have to call their constructor anyway...
I also tried to call the dtor and then the ctor again for those resources
on the pre-existing thread resource to reuse storage, but that didn't work properly
because other code doesn't expect something like that to happen, which breaks assumptions,
and this in turn caused Valgrind to (rightfully) complain about memory bugs.

Note 2: I also had to fix a bug in the core globals destruction because it
always assumed that the thread destroying them was the owning thread,
which on TSRM shutdown isn't always the case. A similar bug was fixed
recently with the JIT globals.

Closes GH-10863.
2023-04-08 16:34:07 +02:00
Niels Dossche
2d2cf3b6e0 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-9397: exif read : warnings and errors : Potentially invalid endianess, Illegal IFD size and Undefined index
2023-04-05 21:37:48 +02:00
Niels Dossche
b81ce297a1 Fix GH-9397: exif read : warnings and errors : Potentially invalid endianess, Illegal IFD size and Undefined index
Don't misinterpret DJI info maker note as DJI maker note.

The DJI and DJI info maker note both share the "DJI" make string.
This caused the current code to try to interpret the DJI info maker note
as a DJI maker note. However, the DJI info maker note requires custom
parsing. Therefore, the misinterpretation actually caused the current
code to believe that there was an unrecoverable error in the IFD for the
maker note by returning false in the maker note parser. This in turn
caused the inability to parse other EXIF metadata.

This patch adds the identification of the DJI info maker note so that it
cannot be misinterpreted. Since we don't implement custom parsing, it
achieves this by setting the tag list to a special marker value (in this
case the NULL pointer). When this marker value is detected, the function
will just skip parsing the maker note and return true. Therefore, the
other code will believe that the IFD is not corrupt.

This approach is similar to handing an unrecognised maker note type
(see the loop on top of exif_process_IFD_in_MAKERNOTE() which also
returns true and treats it as a string). The end result of this patch
is that the DJI info maker note is considered as unknown to the caller of
exif_process_IFD_in_MAKERNOTE(), and therefore that the other EXIF
metadata can be parsed successfully.

Also fix debug output typos in exif.

Closes GH-10470.
2023-04-05 21:35:19 +02:00
Niels Dossche
94a00e9ecd Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix incorrect error handling in dom_zvals_to_fragment()
2023-04-03 21:24:58 +02:00
Niels Dossche
0579beb842 Fix incorrect error handling in dom_zvals_to_fragment()
Discovered this pre-existing problem while testing GH-10682.
Note: this problem existed *before* that PR.

* Not all paths throw a hierarchy request error
* xmlFreeNode must be used instead of xmlFree for the fragment to also
  free its children.
* Free up nodes that couldn't be added when xmlAddChild fails.

I unified the error handling code that's exactly the same with a goto to
prevent at least some of such problems in the future.

Closes GH-10981.
2023-04-03 21:21:35 +02:00
Ilija Tovilo
c4f56c5099
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix add_function_array() assertion when op2 contains op1
2023-04-03 12:49:33 +02:00
Ilija Tovilo
84b4020eb4
Fix add_function_array() assertion when op2 contains op1
Fixes GH-10085
Closes GH-10975
Co-authored-by: Dmitry Stogov <dmitry@zend.com>
2023-04-03 12:48:46 +02:00
Niels Dossche
dd29b66dfa Fix GH-10983: State-dependant segfault in ReflectionObject::getProperties
This is a variant of GH-10200, but in a different place.
Basically, simplexml may create a properties table that's packed instead
of associative. But the macro that was used to loop over the properties
table assumed that it was always associative. Replace it by the macro
that figures it out automatically which one of the two it is.

For test: Co-authored-by: jnvsor

Closes GH-10984.
2023-04-01 20:19:14 +02:00
Niels Dossche
0d12b3db64 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10990: mail() throws TypeError after iterating over $additional_headers array by reference
  Fix GH-8841: php-cli core dump calling a badly formed function
2023-04-01 20:04:48 +02:00
Niels Dossche
79c5b32d15 Fix GH-10990: mail() throws TypeError after iterating over $additional_headers array by reference
We should dereference the values, otherwise references don't work.

Closes GH-10991.
2023-04-01 19:44:43 +02:00
Niels Dossche
cf9b030a57 Fix GH-8841: php-cli core dump calling a badly formed function
It's actually not php-cli specific, nor SAPI specific.
We should delay the registration of the function into the function table
until after the compilation was successful, otherwise the function is
mistakingly registered and a NULL dereference will happen when trying to
call it.

I based my test of Nikita's test, so credits to him for the test:
https://github.com/php/php-src/pull/8933#issuecomment-1259881008

Closes GH-10989.
2023-04-01 19:43:09 +02:00
Ilija Tovilo
d1fc88c726
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix incorrect zval type_flags in preg_replace_callback_array() for immutable arrays
2023-03-31 14:42:35 +02:00
Ilija Tovilo
66ce205718
Fix incorrect zval type_flags in preg_replace_callback_array() for immutable arrays
The ZVAL_ARR macro always set the zval type_info to IS_ARRAY_EX, even if the
hash table is immutable. Since in preg_replace_callback_array() we can return
the passed array directly, and that passed array can be immutable, we need to
reset the type_flags to keep the VM from performing ref-counting on the array.

Fixes GH-10968
Closes GH-10970
2023-03-31 14:41:41 +02:00
Ilija Tovilo
ed80a7e8c9
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Unary minus const expression consistency
2023-03-31 14:28:25 +02:00
Ilija Tovilo
41bbb116dd
Unary minus const expression consistency
- of 0.0 should result in -0.0

Closes GH-10978
2023-03-31 14:27:54 +02:00
Pierrick Charron
960f07104c
[skip ci] Fix PHP 8.2.5 release date in NEWS 2023-03-30 23:30:30 -04: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
cd7d2c8967 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] NEWS
2023-03-30 21:42:17 +02:00
Niels Dossche
5e76c6d264 [ci skip] NEWS 2023-03-30 21:41:11 +02:00
Niels Dossche
4b3eb0b048 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix bug #80602: Segfault when using DOMChildNode::before()
2023-03-30 20:50:23 +02:00
NathanFreeman
2d6decc14c Fix bug #80602: Segfault when using DOMChildNode::before()
This furthermore fixes the logic error explained in
https://github.com/php/php-src/pull/8729#issuecomment-1161737132

Closes GH-10682.
2023-03-30 20:49:05 +02:00
Jakub Zelenka
e80073d3d2
Fix GH-10406: feof() behavior change for UNIX based socket resources
This change restores the old behaviour for the server socket streams
that don't support IO. This is now stored in the stream flags so it can
be later used to do some other decisions and possibly introduce some
better error reporting.

Closes GH-10877
2023-03-30 13:31:46 +01:00
Ben Ramsey
d9df750b22
PHP-8.1 is now for PHP 8.1.19-dev 2023-03-29 19:51:20 -05:00
Pierrick Charron
f7c692a940
PHP-8.2 is now for PHP 8.2.6-dev 2023-03-28 17:27:17 -04:00
Niels Dossche
e9195b21cc Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix undefined behaviour in unpack()
2023-03-28 22:43:53 +02:00
Niels Dossche
87862835e2 Fix undefined behaviour in unpack()
atoi()'s return value is actually undefined when an underflow or
overflow occurs. For example on 32-bit on my system the overflow test
which inputs "h2147483648" results in repetitions==2147483647 and on
64-bit this gives repetitions==-2147483648. The reason the test works on
32-bit is because there's a second undefined behaviour problem:
in case 'h' when repetitions==2147483647, we add 1 and divide by 2.
This is signed-wrap undefined behaviour and accidentally triggers the
overflow check like we wanted to.

Avoid all this trouble and use strtol with explicit error checking.

This also fixes a semantic bug where repetitions==INT_MAX would result
in the overflow check to trigger, even though there is no overflow.

Closes GH-10943.
2023-03-28 22:43:27 +02:00
George Peter Banyard
0ff059c553
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  ext/imap/config.m4: -Werror=implicit-function-declaration compatibility.
2023-03-28 15:19:43 +01:00
Michael Orlitzky
f9cbeaa033
ext/imap/config.m4: -Werror=implicit-function-declaration compatibility.
The recent clang-16 throws errors for implicitly defined functions by
default. In many ./configure tests, an undefined function (which is
"implicitly defined" when you try to call it) is undefined because it
really does not exist. But in one case, utf8_to_mutf7() is undefined
because we forgot to include the header that defines it.

This commit updates the test for utf8_to_mutf7:

  * We now include the header (c-client.h) that defines it.
  * A "checking... yes/no" message was added to the test.
  * The test was switched from PHP_IMAP_TEST_BUILD to AC_COMPILE_IFELSE.
    This was the easiest way to avoid a return-type mismatch that runs
    afoul of -Werror=implicit-int.
  * CPPFLAGS is temporarily amended with the -I flag needed to find
    c-client.h.

Fixes GH-10947.

Closes GH-10948

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-03-28 15:18:18 +01:00
Ilija Tovilo
69c57bea3d
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Reset EG(trampoline).op_array.last_var that FFI may modify
2023-03-27 22:59:58 +02:00
Ilija Tovilo
4e0bd03681
Reset EG(trampoline).op_array.last_var that FFI may modify
Closes GH-10916
2023-03-27 22:59:00 +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
fa1cdfed76 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10908: Bus error with PDO Firebird on RPI with 64 bit kernel and 32 bit userland
2023-03-27 21:14:46 +02:00
Niels Dossche
e698938229 Handle indirect zvals in SplFixedArray::__serialize
Closes GH-10925.
2023-03-27 21:02:29 +02:00
Niels Dossche
21e0305f5d Fix GH-10908: Bus error with PDO Firebird on RPI with 64 bit kernel and 32 bit userland
The alignment of sqldata is in most cases only the basic alignment,
so the code type-puns it to a larger type, it *can* crash due to the
misaligned access. This is only an issue for types > 4 bytes because
every sensible system requires an alignment of at least 4 bytes for
allocated data.

Even though this patch uses memcpy, the compiler is smart enough to
optimise it to something more efficient, especially on x86.
This is just the usual approach to solve these alignment problems.

Actually, unaligned memory access is undefined behaviour, so even on x86
platforms, where the bug doesn't cause a crash, this can be problematic.
Furthermore, even though the issue talks about a 64-bit kernel and
32-bit userspace, this doesn't necessarily need to be the case to
trigger this crash.

Test was Co-authored-by: rvk01

Closes GH-10920.
2023-03-27 21:01:06 +02:00
Ilija Tovilo
c5fe6c2eb9
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix buffer-overflow in php_fgetcsv() with \0 delimiter and enclosure
2023-03-25 17:43:07 +01:00
Ilija Tovilo
57029ce92e
Fix buffer-overflow in php_fgetcsv() with \0 delimiter and enclosure
Fixes oss-fuzz #57392
Closes GH-10923
2023-03-25 17:42:39 +01:00
Ilija Tovilo
834e295f49
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [skip ci] Add NEWS entry
2023-03-25 16:26:46 +01:00
Ilija Tovilo
c2f3a605f0
[skip ci] Add NEWS entry 2023-03-25 16:26:18 +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
Niels Dossche
337973fccc Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-8979: Possible Memory Leak with SSL-enabled MySQL connections
2023-03-24 18:06:53 +01:00
Niels Dossche
8930bf8c33 Fix GH-8979: Possible Memory Leak with SSL-enabled MySQL connections
The stream context inside `mysqlnd_vio::enable_ssl()` is leaking.
In particular: when `php_stream_context_set()` get called the refcount
of `context` is increased by 1, which means that `context` will now
have a refcount of 2. Later on we remove the context from the stream
by calling `php_stream_context_set(stream, NULL)` but that leaves our
`context` with a refcount of 1, and therefore it's never destroyed.
In my test case this yielded a leak of 1456 bytes per connection
(but could be more depending on your settings ofc).

Annoyingly, Valgrind doesn't find it because the context is still
in the `EG(regular_list)` and will thus be destroyed at the end of
the request. However, I still think this bug needs to be fixed because
as the users in the issue report already mentioned:
there can be long-running PHP scripts.

Fix it by decreasing the refcount to transfer the ownership.

Closes GH-10909.
2023-03-24 18:03:29 +01:00
Derick Rethans
cbac68df6b Fix GH-10583: DateTime modify with tz pattern should not update linked timezone 2023-03-23 11:46:31 +00:00
Niels Dossche
57442f8f35 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10521: ftp_get/ftp_nb_get resumepos offset is maximum 10GB
2023-03-20 23:27:46 +01:00
Niels Dossche
301418284d Fix GH-10521: ftp_get/ftp_nb_get resumepos offset is maximum 10GB
The char arrays were too small for a long on 64-bit systems, which
resulted in cutting off the string at the end with a NUL byte. Use a
size of MAX_LENGTH_OF_LONG to fix this issue instead of a fixed size
of 11 chars.

Closes GH-10525.
2023-03-20 23:20:21 +01:00
Niels Dossche
64bb3ef452 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10052: Browscap crashes PHP 8.1.12 on request shutdown (apache2)
2023-03-20 20:57:44 +01:00
Niels Dossche
c407243712 Fix GH-10052: Browscap crashes PHP 8.1.12 on request shutdown (apache2)
get_browser() implements a lazy parse system for the browscap
INI configuration. There are two possible moments when a browscap
configuration can be loaded: during module startup or during request.
In case of module startup, the strings are persistent strings, while for
the request they are not.

The INI parser must therefore know whether to create persistent or
non-persistent strings. It does this by looking at
CG(ini_parser_unbuffered_errors). If that value is 1 it's persistent,
otherwise non-persistent. Note that this also controls how the errors
are reported: if it's 1 then the errors are sent to stderr, otherwise we
get E_WARNINGs.

Currently, a hardcoded value of 1 is always used for that CG value in
browscap_read_file(). This means we'll always create persistent strings
*and* we'll not report parse errors correctly as E_WARNINGs.
We fix both the crash and the lack of warnings by passing the value of
persistent instead of a hardcoded 1.

This is also in line with how other INI parsing code is called in
ext/standard: they also make sure that during request a value of 0 is
passed.

Closes GH-10883.
2023-03-20 20:49:21 +01:00
Ilija Tovilo
3032a68bce
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10885: Leaking stream_socket_server context
2023-03-20 17:45:40 +01:00
Ilija Tovilo
122f1287a0
Fix GH-10885: Leaking stream_socket_server context
`php_stream_context_set` already increases the refcount.

Closes GH-10886
2023-03-20 17:42:16 +01:00
Jakub Zelenka
2b0d29bf17
Merge branch 'PHP-8.1' into PHP-8.2 2023-03-19 13:17:09 +00:00
Jakub Zelenka
0d4d471847
Fix bug #74129: Incorrect SCRIPT_NAME with apache ProxyPassMatch
This happens when there are spaces are in the path info. The reason is
that Apache decodes the path info part in the SCRIPT_NAME as per CGI
RFC. FPM tries to strip path info from the SCRIPT_NAME but the
comparison is done against SCRIPT_FILENAME which is not decoded. For
that to work we have to decode it before comparison if there is any
encoded character.

Closes GH-10869
2023-03-19 13:11:14 +00:00
Ilija Tovilo
c0bb5b0b67
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix NUL byte in exception string terminating Exception::__toString()
2023-03-19 10:50:39 +01:00
Ilija Tovilo
b5726c2cb1
Fix NUL byte in exception string terminating Exception::__toString()
Fixes GH-10810
Closes GH-10873
2023-03-19 10:48:26 +01:00
Niels Dossche
e44b1a916d Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Destroy file_handle in fpm_main
2023-03-18 21:00:21 +01:00
Niels Dossche
f30e71cbde Destroy file_handle in fpm_main
If it's not in the CG(open_files) list, we need to destroy the file
handle ourselves.

Co-authored-by: Jakub Zelenka <bukka@php.net>

Closes GH-10707.
2023-03-18 20:54:46 +01:00
Niels Dossche
d479b5a0e7 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-8789 and GH-10015: Fix ZTS zend signal crashes due to NULL globals
2023-03-18 11:45:06 +01:00
Niels Dossche
06ae75007a Fix GH-8789 and GH-10015: Fix ZTS zend signal crashes due to NULL globals
Fixes GH-8789.
Fixes GH-10015.

This is one small part of the underlying bug for GH-10737, as in my
attempts to reproduce the issue I constantly hit this crash easily.
(The fix for the other underlying issue for that bug will follow soon.)

It's possible that a signal arrives at a thread that never handled a PHP
request before. This causes the signal globals to dereference a NULL
pointer because the TSRM pointers for the thread aren't set up to point
to the thread resources yet.

PR GH-9766 previously fixed this for master by ignoring the signal if
the thread didn't handle a PHP request yet. While this fixes the crash
bug, I think the solution is suboptimal for 3 reasons:

1) The signal is ignored and a message is printed saying there is a bug.
   However, this is not a bug at all. For example in Apache, the signal
   set up happens on child process creation, and the thread resource
   creation happens lazily when the first request is handled by the
   thread. Hence, the fact that the thread resources aren't set up yet
   is not actually buggy behaviour.

2) I believe since it was believed to be buggy behaviour, that fix was
   only applied to master, so 8.1 & 8.2 keep on crashing.

3) We can do better than ignoring the signal. By just acting in the
   same way as if the signals aren't active. This means we need to
   take the same path as if the TSRM had already shut down.

Closes GH-10861.
2023-03-18 11:44:29 +01:00
David Carlier
892f833807 Merge branch 'PHP-8.1' into PHP-8.2 2023-03-18 07:10:06 +00:00
David CARLIER
5adeed3051 ext/psql: pg_meta_data, extended mode, fix typo for pseudo typtype.
Closes GH-10865.
2023-03-18 07:09:13 +00:00
Michael Voříšek
5239f9fc86 Remove CTE flag from array_diff_ukey(), which was added by mistake
This was accidentally added in GH-7780, but since it takes a callable
argument, this flag is useless on this function.

Closes GH-10859.
2023-03-15 21:40:11 +01:00