Commit graph

63106 commits

Author SHA1 Message Date
Dmitry Stogov
cec528d06b Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix assertion failure when var_dump'ing void FFI result (#10568)
2023-02-13 22:38:43 +03:00
Niels Dossche
1a5fc6e1a3
Fix assertion failure when var_dump'ing void FFI result (#10568) 2023-02-13 22:38:28 +03:00
Stanislav Malyshev
e8c64b62da Merge branch 'PHP-8.1' into PHP-8.2 2023-02-12 21:34:10 -07:00
Stanislav Malyshev
85d9278db2 Merge branch 'PHP-8.0' into PHP-8.1 2023-02-12 21:33:39 -07:00
Niels Dossche
ec10b28d64 Fix array overrun when appending slash to paths
Fix it by extending the array sizes by one character. As the input is
limited to the maximum path length, there will always be place to append
the slash. As the php_check_specific_open_basedir() simply uses the
strings to compare against each other, no new failures related to too
long paths are introduced.
We'll let the DOM and XML case handle a potentially too long path in the
library code.
2023-02-12 20:56:19 -07:00
Tim Düsterhus
a92acbad87 crypt: Fix possible buffer overread in php_crypt() 2023-02-12 20:46:51 -07:00
Tim Düsterhus
c840f71524 crypt: Fix validation of malformed BCrypt hashes
PHP’s implementation of crypt_blowfish differs from the upstream Openwall
version by adding a “PHP Hack”, which allows one to cut short the BCrypt salt
by including a `$` character within the characters that represent the salt.

Hashes that are affected by the “PHP Hack” may erroneously validate any
password as valid when used with `password_verify` and when comparing the
return value of `crypt()` against the input.

The PHP Hack exists since the first version of PHP’s own crypt_blowfish
implementation that was added in 1e820eca02.

No clear reason is given for the PHP Hack’s existence. This commit removes it,
because BCrypt hashes containing a `$` character in their salt are not valid
BCrypt hashes.
2023-02-12 20:46:44 -07:00
Derick Rethans
ada261557b Merge remote-tracking branch 'derickr/ossfuzz-unserialise-fixes' into PHP-8.2 2023-02-10 14:45:07 +00:00
George Peter Banyard
d8cec14c11
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix memory leaks in ext-tidy
2023-02-10 14:16:38 +00:00
George Peter Banyard
704aadd098
Fix memory leaks in ext-tidy
We must not instantiate the object prior checking error conditions
Moreover, we need to release the HUGE amount of memory for files which are over 4GB when throwing a ValueError

Closes GH-10545
2023-02-10 14:12:23 +00:00
Derick Rethans
5d9ee8f920 Fixed OSS fuzz issues #55589, #55599, and #55727 2023-02-10 13:03:47 +00:00
Arnaud Le Blanc
10f2378584 Fix concurrent testing 2023-02-10 13:31:57 +01:00
Niels Dossche
b4db690cb3
Fix GH-10370: File corruption in _php_stream_copy_to_stream_ex when using copy_file_range (#10440)
copy_file_range can return early without copying all the data. This is
legal behaviour and worked properly, unless the mmap fallback was used.
The mmap fallback would read too much data into the destination,
corrupting the destination file. Furthermore, if the mmap fallback would
fail and have to fallback to the regular file copying mechanism, a
similar issue would occur because both maxlen and haveread are modified.
Furthermore, there was a mmap-resource in one of the failure paths of
the mmap fallback code.
This patch fixes these issues. This also adds regression tests using the
new copy_file_range early-return simulation added in the previous
commit.
2023-02-10 13:08:44 +01:00
David Carlier
81aedad452 opcache/pcntl/cli: Fixes few functions signatures. 2023-02-09 19:57:48 +00:00
David Carlier
06120df71e Merge branch 'PHP-8.1' into PHP-8.2 2023-02-08 18:32:33 +00:00
Max Kellermann
8c8a38a75c ext/curl: suppress -Wdeprecated-declarations
Closes GH-10531.
2023-02-08 18:32:13 +00:00
Max Kellermann
0752baa583 Zend/zend_cpuinfo, ext/standard/crc32_x86: fix -Wstrict-prototypes
In plain C, a function without arguments must be explicitly declared
(void).

Close GH-10528
2023-02-07 22:47:43 +00:00
Ben Ramsey
26e10258ce
Merge branch 'PHP-8.1' into PHP-8.2 2023-02-07 09:29:39 -06:00
Michael Voříšek
4df4264ac9
Fix PDO OCI Bug #60994 (Reading a multibyte CLOB caps at 8192 chars) 2023-02-07 09:25:34 -06:00
Dmitry Stogov
d948b858de Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  ext/opcache/zend_jit: call TSRM dtor before unloading opcache.so (#10533)
2023-02-07 16:09:46 +03:00
Max Kellermann
131b862ac0
ext/opcache/zend_jit: call TSRM dtor before unloading opcache.so (#10533)
Commit a21195650e added a TSRM destructor, but that destructor
will get called by tsrm_shutdown(), which is after opcache.so has
already been unloaded, resulting in a shutdown crash, e.g.:

  #0  0x00007fad01737500 in ?? ()
  #1  0x000055ac54e723c4 in tsrm_shutdown () at TSRM/TSRM.c:194
  #2  0x000055ac54c42180 in main (argc=80, argv=0x55ac57bc14d0) at sapi/cli/php_cli.c:1388

By calling ts_free_id() before opcache.so gets unloaded, we can easily
fix this crash bug.
2023-02-07 16:09:17 +03:00
Dmitry Stogov
8ad81c0e8c Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  ext/opcache/zend_jit: cast function to fix -Wincompatible-pointer-types (#10527)
2023-02-07 13:38:39 +03:00
Max Kellermann
afbb28dfb7
ext/opcache/zend_jit: cast function to fix -Wincompatible-pointer-types (#10527)
* ext/opcache/zend_jit: cast function to fix -Wincompatible-pointer-types

Regression by commit a21195650e

* TSRM/win32: fix ts_allocate_dtor cast

The dtor was casted to ts_allocate_ctor; luckily, ts_allocate_dtor and
ts_allocate_ctor just happen to be the same type.
2023-02-07 13:38:17 +03:00
Dmitry Stogov
29efbe593d Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix possible exit_counters memory leak in ZTS build
2023-02-06 18:37:24 +03:00
Dmitry Stogov
a21195650e Fix possible exit_counters memory leak in ZTS build 2023-02-06 18:35:06 +03:00
Tyson Andre
e3f04ddb0b Merge branch 'PHP-8.1' into PHP-8.2 2023-02-03 09:18:03 -05:00
Tyson Andre
fe2dc2b481
Avoid crash for reset/end/next/prev() on ffi classes (#9711)
(And any PECLs returning `zend_empty_array` in the handler->get_properties
overrides)

Closes GH-9697

This is similar to the fix used in d9651a9419
for array_walk.

This should make it safer for php-src (and PECLs, long-term) to return
the empty immutable array in `handler->get_properties` to avoid wasting memory.
See https://github.com/php/php-src/issues/9697#issuecomment-1273613175

The only possible internal iterator position for the empty array is at the end
of the empty array (nInternalPointer=0).
The `zend_hash*del*` helpers will always set nInternalPointer to 0 when an
array becomes empty,
regardless of previous insertions/deletions/updates to the array.
2023-02-03 09:17:33 -05:00
Derick Rethans
cb907d50a8 Merge branch 'PHP-8.1' into PHP-8.2 2023-01-31 13:00:06 +00:00
Derick Rethans
a42bf93308 Fixed GH-10447: 'p' format specifier does not yield 'Z' for 00:00 2023-01-31 12:58:21 +00:00
Derick Rethans
85fbc6eaa6 Fix GH-10152: Custom properties of Date's child classes are not serialised 2023-01-31 12:53:03 +00:00
Dmitry Stogov
55e3f73109 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix type inference
2023-01-30 13:16:05 +03:00
Dmitry Stogov
81607a62ca Fix type inference
Fixes oss-fuzz #55358
2023-01-30 13:15:05 +03:00
George Peter Banyard
08f654b590
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix incorrect check in phar tar parsing
2023-01-29 17:17:21 +00:00
Niels Dossche
ec4939b170
Fix incorrect check in phar tar parsing
The entry.flags was used to check whether the entry has the directory
flag. The flags however were masked to only contain the permissions. We
need to check the mode, before the permission masking, instead of the
flags to check whether it is a directory.

Closes GH-10464

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-01-29 17:14:12 +00:00
Arnaud Le Blanc
6c22dea3c1 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] NEWS
  Fix overflow check in OnUpdateMemoryConsumption (#10456)
  Prevent dtor of generator in suspended fiber (#10462)
2023-01-27 19:37:01 +01:00
Niels Dossche
d7de73b551
Fix overflow check in OnUpdateMemoryConsumption (#10456)
memsize is a signed long, therefore the check against the
(*un*signed long maximum) / 1024² will allow too large values. This check worked
correctly in d4b3f89c53 where it checked against the maximum signed
value, but was broken in 003346c450. Fix it by changing ZEND_ULONG_MAX
to ZEND_LONG_MAX.
2023-01-27 19:33:58 +01:00
Derick Rethans
639bfbc217 Sync timelib to 2022.05 to address OSS Fuzzer issues 2023-01-25 10:49:48 +00:00
George Peter Banyard
0d9bf101c4
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix incorrect check in cs_8559_5 in map_from_unicode()
  Fix incorrect page_size check
2023-01-25 00:10:56 +00:00
Niels Dossche
a8c8fb2564
Fix incorrect check in cs_8559_5 in map_from_unicode()
The condition `code == 0x0450 || code == 0x045D` is always false because
of an incorrect range check on code.
According to the BMP coverage in the encoding spec for ISO-8859-5
(https://encoding.spec.whatwg.org/iso-8859-5-bmp.html) the range of
valid characters is 0x0401 - 0x045F (except for 0x040D, 0x0450, 0x045D).
The current check has an upper bound of 0x044F instead of 0x045F.
Fix this by changing the upper bound.

Closes GH-10399

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-01-25 00:08:28 +00:00
Niels Dossche
b7a158a19b
Fix incorrect page_size check
The current check always evaluated to false because if `!page_size`
is true, then `page_size & (page_size - 1)` equals `0 & (0 - 1)` which
is always 0. The if condition is meant to check if page_size is zero or
not a power of two, thus we must change the AND to an OR to fix this
issue.

Closes GH-10427

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-01-25 00:06:56 +00:00
Máté Kocsis
7517cf3b97
Merge branch 'PHP-8.1' into PHP-8.2
- PHP-8.1:
  Fix GH-10292 1st param of mt_srand() has UNKNOWN default on PHP <8.3
2023-01-24 19:53:09 +01:00
Máté Kocsis
3197104e85
Fix GH-10292 1st param of mt_srand() has UNKNOWN default on PHP <8.3
Closes GH-10429
2023-01-24 19:05:33 +01:00
Dmitry Stogov
d5b307c434 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix incorrect bitshifting and masking in ffi bitfield (#10403)
2023-01-24 09:15:27 +03:00
Niels Dossche
560ca9c7ae
Fix incorrect bitshifting and masking in ffi bitfield (#10403)
When a uint8_t is bitshifted to the left, it is actually promoted to an
int. For the current code this has the effect of a wrong sign-extension,
and the result will also wrongly become zero when insert_pos >= 32.
Fix this by adding an explicit cast.
Furthermore, the partial prefix byte mask was computed incorrectly: the
byte is already shifted so the mask should not account for the shift.
2023-01-24 09:15:03 +03:00
Tim Düsterhus
57b362b7a9
random: Do not trust arc4random_buf() on glibc (#10390)
This effectively reverts #8984.

As discussed in #10327 which will enable the use of the getrandom(2) syscall on
NetBSD instead of relying on the userland arc4random_buf(), the CSPRNG should
prioritize security over speed [1] and history has shown that userland
implementations unavoidably fall short on the security side. In fact the glibc
implementation is a thin wrapper around the syscall due to security concerns
and thus does not provide any benefit over just calling getrandom(2) ourselves.

Even without any performance optimizations the CSPRNG should be plenty fast for
the vast majority of applications, because they often only need a few bytes of
randomness to generate a session ID. If speed is desired, the OO API offers
faster, but non-cryptographically secure engines.
2023-01-23 18:21:42 +01:00
George Peter Banyard
81732056fe
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix duplicated FILE section in test bug80747.phpt
2023-01-23 13:51:13 +00:00
Niels Dossche
974dba3b80
Fix duplicated FILE section in test bug80747.phpt
Signed-off-by: George Peter Banyard <girgias@php.net>
2023-01-23 13:50:49 +00:00
Arnaud Le Blanc
c2e77f9c0f Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] NEWS
  Fix GH-10248: Assertion `!(zval_get_type(&(*(property))) == 10)' failed.
2023-01-20 16:52:52 +01:00
Niels Dossche
0801c567dc Fix GH-10248: Assertion `!(zval_get_type(&(*(property))) == 10)' failed.
The assertion failure was triggered in a debug code-path that validates
property types for internal classes.
zend_verify_internal_read_property_type was called with retval being a
reference, which is not allowed because that function eventually calls to
i_zend_check_property_type, which does not expect a reference.
The non-debug code-path already takes into account that retval can be a
reference, as it optionally dereferences retval.

Add a dereference in zend_verify_internal_read_property_type just before
the call to zend_verify_property_type, which is how other callers often
behave as well.
2023-01-20 16:40:15 +01:00
Jakub Zelenka
cc931af35d
Fix GH-8086: Introduce mail.mixed_lf_and_crlf INI
When this INI option is enabled, it reverts the line separator for
headers and message to LF which was a non conformant behavior in PHP 7.
It is done because some non conformant MTAs fail to parse CRLF line
separator for headers and body.

This is used for mail and mb_send_mail functions.
2023-01-19 19:05:39 +00:00