Commit Graph

5958 Commits

Author SHA1 Message Date
Pierrick Charron
c69c84a5f6
PHP-8.2 is now for PHP 8.2.21-dev 2024-05-21 14:32:07 -04:00
Niels Dossche
ad5138a341
Fix undefined behaviour in fastcgi.c (#14269)
Arithmetic on NULL pointers is undefined.
2024-05-19 22:54:06 +02:00
David Carlier
74843947f4
sapi/cgi: fix buffer limit on windows.
MSDN recommends dropping the deprecated `read` in favor of `_read`.
Also, the buffer size limit is INT_MAX.

Close GH-14022
2024-05-01 13:58:53 +01:00
Sergey Panteleev
3b5321dffe
PHP-8.2 is now for PHP 8.2.20-dev 2024-04-23 17:22:54 +03:00
Niels Dossche
c3acfb1b57
Fix GH-13931: Applying zero offset to null pointer in Zend/zend_opcode.c
In the test cases, the compiler bails out due to a fatal error.
The data structures used by the compiler will contain stale values.
In particular, for the test case CG(loop_var_stack) will contain data.
The next compilation will incorrectly use elements from the previous
stack.
To solve this, we reset part of the compiler data structures.
We don't do a full re-initialization via init_compiler() because that will
also reset streams and resources.

Closes GH-13938.
2024-04-15 19:39:05 +02:00
Damian Wójcik
8421cfda61
Fix file_get_contents() on Windows fails with "errno=22 Invalid argument"
Closes GH-13948
2024-04-14 14:26:10 +01:00
Ben Ramsey
a9ffc447a4
Merge branch 'PHP-8.1' into PHP-8.2 2024-04-09 23:49:31 -05:00
Niels Dossche
093c08af25
Fix GHSA-wpj3-hf5j-x4v4: __Host-/__Secure- cookie bypass due to partial CVE-2022-31629 fix
The check happened too early as later code paths may perform more
mangling rules. Move the check downwards right before adding the actual
variable.
2024-04-09 23:37:06 -05:00
Arnaud Le Blanc
577b8ae422
Fix cookie_seek_function_t signature under musl (#13890)
Fixes GH-11678
2024-04-08 14:58:12 +02:00
Cristian Rodríguez
18d70db091
Fix gcc-14 Wcalloc-transposed-args warnings
gcc-14 and later warns of inverted arguments in calloc or
calloc-like __alloc_size__ annotated functions.

Closes GH-13818.
2024-04-01 20:34:14 +02:00
Jakub Zelenka
c087398cc2
Fix GH-13264: Part 1 - Memory leak on filter failure
Closes GH-13790
2024-03-29 16:06:49 +00:00
Pierrick Charron
7942268899
PHP-8.2 is now for PHP 8.2.19-dev 2024-03-26 08:49:44 -04:00
divinity76
2343791aff
Fix GH-13203: file_put_contents fail on strings over 4GB on Windows
Closes GH-13205
2024-03-09 19:58:28 +00:00
Sergey Panteleev
e1a8ebd61b
PHP-8.2 is now for PHP 8.2.18-dev 2024-02-27 17:26:44 +03:00
Jakub Zelenka
bc30ae4f04
Fix bug #75712: getenv in php-fpm should not read $_ENV, $_SERVER
Closes GH-13195
2024-02-04 11:58:18 +00:00
Pierrick Charron
0454f4ade4
PHP-8.2 is now for PHP 8.2.17-dev 2024-01-30 12:43:37 -05:00
Niels Dossche
5e9e9c9d51 Fix GH-13071: Copying large files using mmap-able source streams may exhaust available memory and fail
Commit 5cbe5a538c disabled chunking for all writes to streams. However,
user streams have a callback where code is executed on data that is
subject to the memory limit. Therefore, when using large writes or
stream_copy_to_stream/copy the memory limit can easily be hit with large
enough data.

To solve this, we reintroduce chunking for userspace streams.
Users have control over the chunk size, which is neat because
they can improve the performance by setting the chunk size if
that turns out to be a bottleneck.

In an ideal world, we add an option so we can "ask" the stream whether
it "prefers" chunked writes, similar to how we have
php_stream_mmap_supported & friends. However, that cannot be done on
stable branches.

Closes GH-13136.
2024-01-16 23:44:58 +01:00
Niels Dossche
2cde4b2ea4 Fix GH-13097: Anonymous class reference in trigger_error / thrown Exception
Closes GH-13153.
2024-01-16 21:05:04 +01:00
Sergey Panteleev
5d79c1b74d
PHP-8.2 is now for PHP 8.2.16-dev 2024-01-02 16:42:14 +03:00
Jakub Zelenka
40ccc8ea7e
Fix GH-9698: stream_wrapper_register crashes with FFI\CData provided as class
Closes GH-12926
2023-12-15 14:11:56 +00:00
Pierrick Charron
dc3641ea0f
PHP-8.2 is now for PHP 8.2.15-dev 2023-12-05 15:01:08 -05:00
Patrick Allaert
8f6610ce88
PHP-8.1 is now for PHP 8.1.28-dev
(If released one day!)
2023-12-05 15:05:00 +01:00
Ilija Tovilo
daa38dd63e
Fix in-place modification of filename in php_message_handler_for_zend
php_strip_url_passwd modifies url in-place. We cannot assume from
php_message_handler_for_zend that data is a temporary, modifiable string.

Fixes oss-fuzz #64209
Closes GH-12733
2023-11-22 21:09:42 -06:00
Jakub Zelenka
e43ffb5023
Fix stream fclose_stdiocast_flush_in_progress type 2023-11-22 20:39:30 -06:00
Jakub Zelenka
a7a6151c4f
Fix bug #79945: Stream wrappers in imagecreatefrompng causes segfault
Closes GH-12696
2023-11-22 20:39:30 -06:00
Ilija Tovilo
d8e866da04
Fix in-place modification of filename in php_message_handler_for_zend
php_strip_url_passwd modifies url in-place. We cannot assume from
php_message_handler_for_zend that data is a temporary, modifiable string.

Fixes oss-fuzz #64209
Closes GH-12733
2023-11-20 14:12:25 +01:00
Jakub Zelenka
4da89d86ec
Fix stream fclose_stdiocast_flush_in_progress type 2023-11-17 13:33:55 +00:00
Jakub Zelenka
6734880ef5
Fix bug #79945: Stream wrappers in imagecreatefrompng causes segfault
Closes GH-12696
2023-11-17 13:26:42 +00:00
Ben Ramsey
55dfc29539
PHP-8.1 is now for PHP 8.1.27-dev 2023-11-07 14:28:31 -06:00
Sergey Panteleev
239a26fa90
PHP-8.2 is now for PHP 8.2.14-dev 2023-11-07 17:12:19 +03:00
Jakub Zelenka
e3d1beb0f1
Fix bug #76922: FastCGI terminates conn after FCGI_GET_VALUES
Closes GH-12387
2023-11-03 14:06:36 +00:00
Patrick Allaert
be64db5939
PHP-8.1 is now for PHP 8.1.26-dev 2023-10-10 22:54:03 +02:00
Pierrick Charron
2642a08697
PHP-8.2 is now for PHP 8.2.13-dev 2023-10-10 11:45:26 -04:00
David Carlier
4bfd3459fe Merge branch 'PHP-8.1' into PHP-8.2 2023-09-24 15:19:02 +01:00
David Carlier
d65c80031a Fix GH-12190: stream_context_create with address and port at 0.
Prior to the 8.1 rewrite, inet_aton was used for ipv4 addresses
therefore addresses like `0` passed.
For the bindto's case where both ip and port are set as such, we discard
the address binding.

Close GH-12195
2023-09-24 15:17:53 +01: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
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
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
Sergey Panteleev
796a75f967
PHP-8.2 is now for PHP 8.2.10-dev 2023-07-18 14:02:43 +03: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
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
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
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