1
0
mirror of https://github.com/php/php-src.git synced 2026-03-29 19:52:20 +02:00
Commit Graph

5988 Commits

Author SHA1 Message Date
Sergey Panteleev
769e1b521b Update versions for PHP 8.2.27 2024-12-17 14:39:23 +03:00
Niels Dossche
aab784263d Fix GH-16998: UBSAN warning in rfc1867
The "else branch" of `next_line` can reset the `buf_begin` field to
NULL, causing the next invocation to pass NULL to `memchr` with a 0
length. When UBSAN is enabled this causes an UBSAN abort. Real world
impact is likely none because of the 0 length.

To fix this, don't set the pointer to NULL, which means that the
`memchr` will return NULL and since
`self->bytes_in_buffer < self->bufsize` we return NULL and request more
data through `fill_buffer`. That function will reset `buf_begin` and
`bytes_in_buffer` so that the next invocation works fine.

I chose this solution so we have an invariant that `buf_begin` is never
NULL, which makes reasoning easier. An alternative solution is keeping
the NULLing of `buf_begin` and add an extra check at the top of
`next_line`, but I didn't like special casing this.

Closes GH-17000.
2024-12-01 10:59:30 +01:00
Jakub Zelenka
69765d9220 Fix network connect poll interuption handling
When connecting to socket, it is possible to get EINTR. In such case,
there should be an another attempt to connect if we are not over the
timeout. The timeout should be adjusted accordingly in that case.

This fixes https://github.com/phpredis/phpredis/issues/1881

Closes GH-16606
2024-11-29 07:54:06 +01:00
Christoph M. Becker
e75061b512 Fix GH-16849: Error dialog causes process to hang
If `_DEBUG` is set, assertion failures and errors are directed to a
debug message window by default[1].  That causes a process to hang,
since these dialogs are modal.  While we already cater to assertion
failures, errors have apparently been overlooked.

We choose a minimal fix for BC reasons; although passing `0` as
`reportMode` is undocumented, it obviously works fine for a long time.
We may consider to improve on this for the `master` branch.

[1] <https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/crtsetreportmode>

Closes GH-16850.
2024-11-25 23:04:51 +01:00
Pierrick Charron
f5895792e7 PHP-8.2 is now for PHP 8.2.27-dev 2024-11-05 12:47:25 -05:00
Sergey Panteleev
5f5824015c PHP-8.2 is now for PHP 8.2.26-dev 2024-10-08 19:53:22 +05:00
Jakub Zelenka
5a47f27021 Fix GH-15395: php-fpm: zend_mm_heap corrupted with cgi-fcgi request
Closes GH-16227

Co-authored-by: David Carlier <devnexen@gmail.com>
2024-10-06 19:37:55 +01:00
David Carlier
332b067c5e Fix GH-15937: stream timeout option overflow.
close GH-15942
2024-09-30 18:10:33 +01:00
Ben Ramsey
c259c9f3f6 Merge branch 'PHP-8.1' into PHP-8.2 2024-09-26 13:13:46 -05:00
Ben Ramsey
fcbcf2f281 PHP-8.1 is now for PHP 8.1.31-dev 2024-09-26 12:52:41 -05:00
Christoph M. Becker
87d59d7fdd Fix GH-15905: Assertion failure for TRACK_VARS_SERVER
When the superglobals are eagerly initialized, but "S" is not contained
in `variables_order`, `TRACK_VARS_SERVER` is created as empty array
with refcount > 1.  Since this hash table may later be modified, a flag
is set which allows such COW violations for assertions.  However, when
`register_argc_argv` is on, the so far uninitialized hash table is
updated with `argv`, what causes the hash table to be initialized, what
drops the allow-COW-violations flag.  The following update with `argc`
then triggers a refcount violation assertion.

Since we consider `HT_ALLOW_COW_VIOLATION` a hack, we do not want to
keep the flag during hash table initialization, so we initialize the
hash table right away after creation for this code path.

Closes GH-15930.
2024-09-26 15:33:35 +02:00
Christoph M. Becker
81916758ec Fix GH-15980: Signed integer overflow in main/streams/streams.c
We need to avoid signed integer overflows which are undefined behavior.
We catch that, and set `offset` to `ZEND_LONG_MAX` (which is also the
largest value of `zend_off_t` on all platforms).  Of course, that seek
may fail, but even if it succeeds, the stream is no longer readable,
but that matches the current behavior for offsets near `ZEND_LONG_MAX`.

Closes GH-15989.
2024-09-24 12:32:00 +02:00
Arnaud Le Blanc
d65a1e6f91 Fix GHSA-9pqp-7h25-4f32
multipart/form-data boundaries larger than the read buffer result in erroneous
parsing, which violates data integrity.

Limit boundary size, as allowed by RFC 1521:

    Encapsulation boundaries [...] must be no longer than 70 characters, not
    counting the two leading hyphens.

We correctly parse payloads with boundaries of length up to
FILLUNIT-strlen("\r\n--") bytes, so allow this for BC.
2024-09-23 11:23:13 +01:00
Christoph M. Becker
ee95ee7216 Revert "Fix GH-15980: Signed integer overflow in main/streams/streams.c"
This reverts commit 6a04c79e41, since the
new test case apparently fails on 64bit Linux, so this needs closer
investigation.
2024-09-23 01:31:05 +02:00
Christoph M. Becker
6a04c79e41 Fix GH-15980: Signed integer overflow in main/streams/streams.c
We need to avoid signed integer overflows which are undefined behavior.
We catch that, and set `offset` to `ZEND_LONG_MAX` (which is also the
largest value of `zend_off_t` on all platforms).  Of course, after such
a seek a stream is no longer readable, but that matches the current
behavior for offsets near `ZEND_LONG_MAX`.

Closes GH-15989.
2024-09-23 00:28:09 +02:00
Niels Dossche
018c0b3d14 Fix GH-15908 and GH-15026: leak / assertion failure in streams.c
This was first reported as a leak in GH-15026, but was mistakingly
believed to be a false positive. Then an assertion was added and it got
triggered in GH-15908. This fixes the leak. Upon merging into master the
assertion should be removed as well.

Closes GH-15924.
2024-09-22 16:07:12 +02:00
Pierrick Charron
7e722e3ba4 PHP-8.2 is now for PHP 8.2.25-dev 2024-09-10 15:26:28 -04:00
Christoph M. Becker
93021c635d Fix GH-15628: php_stream_memory_get_buffer() not zero-terminated
We're reasonably sure that appending the NUL is not an OOB write, since
the memory stream implementation uses `zend_string` APIs instead of
fiddling with the buffer.

We don't add a regression test because that would require to set up
something in the zend_test extension, and regressions are supposed
to be caught by external consumers of this API, such as mailparse.

Closes GH-15648.
2024-09-01 14:55:40 +02:00
Niels Dossche
4b6575a1f9 Fix GH-15565: --disable-ipv6 during compilation produces error EAI_SYSTEM not found
Closes GH-15567.
2024-08-24 14:14:20 +02:00
Sergey Panteleev
84d8fa9f53 PHP-8.2 is now for PHP 8.2.24-dev 2024-08-13 17:18:16 +03:00
Niels Dossche
40551dd74b Fix uninitialized memory in network.c
See https://github.com/php/php-src/issues/14806#issuecomment-2208150509
and https://github.com/php/php-src/issues/14806#issuecomment-2208690481

Closes GH-15068.
2024-07-22 22:25:28 +02:00
Pierrick Charron
e07813ad46 PHP-8.2 is now for PHP 8.2.23-dev 2024-07-16 12:20:55 -04:00
Niels Dossche
89c3e0346a Fix GH-14808: Unexpected null pointer in Zend/zend_string.h with empty output buffer
The output buffer can be NULL when the number of bytes is zero.

Closes GH-14815.
2024-07-04 15:49:58 +02:00
Arnaud Le Blanc
3fbca7fb6a Support sysconf(_SC_GETPW_R_SIZE_MAX) == -1 (#13922) 2024-06-24 19:52:55 +02:00
Sergey Panteleev
49aaa7cd9f PHP-8.2 is now for PHP 8.2.22-dev 2024-06-18 17:56:05 +03:00
Derick Rethans
ad56ec7bbf Fixed off-by-one error in checking length of abtract namespace Unix sockets 2024-06-13 12:46:22 +01:00
Kévin Dunglas
c47d357db5 Set SG(rfc1867_uploaded_files) to null after destroy
Closes GH-14499
2024-06-10 23:02:56 +02:00
Niels Dossche
bc558bf7a3 Fix GH-11078: PHP Fatal error triggers pointer being freed was not allocated and malloc: double free for ptr errors
Although the issue was demonstrated using Curl, the issue is purely in
the streams layer of PHP.

Full analysis is written in GH-11078 [1], but here is the brief version:
Here's what actually happens:
1) We're creating a FILE handle from a stream using the casting mechanism.
   This will create a cookie-based FILE handle using funopen.
2) We're reading stream data using fread from the userspace stream. This will
   temporarily set a buffer into a field _bf.base [2]. This buffer is now equal
   to the upload buffer that Curl allocated and note that that buffer is owned
   by Curl.
3) The fatal error occurs and we bail out from the fread function, notice how
   the reset code is never executed and so the buffer will still point to
   Curl's upload buffer instead of FILE's own buffer [3].
4) The resources are destroyed, this includes our opened stream and because the
   FILE handle is cached, it gets destroyed as well.
   In fact, the stream code calls through fclose on purpose in this case.
5) The fclose code frees the _bs.base buffer [4].
   However, this is not the buffer that FILE owns but the one that Curl owns
   because it isn't reset properly due to the bailout!
6) The objects are getting destroyed, and so the curl free logic is invoked.
   When Curl tries to gracefully clean up, it tries to free the buffer.
   But that buffer is actually already freed mistakingly by the C library!

This also explains why we can't reproduce it on Linux: this bizarre buffer
swapping only happens on macOS and BSD, not on Linux.

To solve this, we switch to an unbuffered mode for cookie-based FILEs.
This avoids any stateful problems related to buffers especially when the
bailout mechanism triggers. As streams have their own buffering
mechanism, I don't expect this to impact performance.

[1] https://github.com/php/php-src/issues/11078#issuecomment-2155616843
[2] 5e566be7a7/stdio/FreeBSD/fread.c (L102-L103)
[3] 5e566be7a7/stdio/FreeBSD/fread.c (L117)
[4] 5e566be7a7/stdio/FreeBSD/fclose.c (L66-L67)

Closes GH-14524.
2024-06-10 19:38:21 +02:00
Ben Ramsey
a87ccc7ca2 PHP-8.1 is now for PHP 8.1.30-dev 2024-06-05 00:48:17 -05:00
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
ca5fe4030c PHP-8.1 is now for PHP 8.1.29-dev 2024-04-10 00:48:59 -05: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