Commit graph

63260 commits

Author SHA1 Message Date
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
Niels Dossche
1357d1eb41 Fix test for GH-10908
It turns out that the version of Firebird influences the test in terms
of supported data types. On Windows on 8.2 we seem to be using a
different version than on 8.1. Fix it by amending the test.
The core issue is still tested in the test, it's just that not all
datatypes are tested anymore (which isn't strictly necessary anyway).
2023-03-28 00:11:17 +02: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
Dmitry Stogov
1f5d9534ae Fix incorrect optimization
Fixes oss-fuzz #57482
2023-03-27 17:57:54 +03:00
Ilija Tovilo
9b15537e9a
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Unparallelize IO heavy tests
2023-03-27 16:34:11 +02:00
Ilija Tovilo
e1ec67acd6
Unparallelize IO heavy tests
Alternative to GH-10892. This is somewhat unfortunate since these are also the
slow tests. I'm also not sure if this actually helps.

Closes GH-10953
2023-03-27 16:33:36 +02:00
Niels Dossche
22040f5a8f Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix undefined behaviour in GENERATE_SEED()
  Fix undefined behaviour when writing 32-bit values in phar/tar.c
2023-03-26 16:15:57 +02:00
Niels Dossche
6f56c00498 Fix undefined behaviour in GENERATE_SEED()
Signed multiply overflow is undefined behaviour.
If you run the CI tests with UBSAN enabled on a 32-bit platform, this is
quite easy to hit. On 64-bit it's more difficult to hit though, but not
impossible.

Closes GH-10942.
2023-03-26 16:07:39 +02:00
Niels Dossche
19ddc62778 Fix undefined behaviour when writing 32-bit values in phar/tar.c
As shown on the CI runs on my fork (which runs with UBSAN),
the pointers can sometimes be unaligned when trying to write.
This is UB and on platforms like ARM this *can* result in a bus error.
Replace it with memcpy, which at least on x86 and powerpc
architectures does result in the same assembly code.

Closes GH-10940.
2023-03-26 16:06:29 +02:00
Niels Dossche
93e0f6b424 Fix undefined behaviour in string uppercasing and lowercasing
At least on 32-bit, the address computations overflow in running the
test on CI with UBSAN enabled. Fix it by reordering the arithmetic.
Since a part of the expression is already used in the code above the
computation, this should not negatively affect performance.

Closes GH-10936.
2023-03-25 21:17:15 +01:00
David Carlier
3e05059e00 Merge branch 'PHP-8.1' into PHP-8.2 2023-03-25 17:41:45 +00:00
David CARLIER
f6989df8cc ext/pdo_mysql: mysql_handle_closer nullify some freed data.
Close GH-10926
2023-03-25 17:41:21 +00:00
Niels Dossche
a095203a03 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10928: PHP Build Failed - Test curl_version() basic functionality [ext/curl/tests/curl_version_basic_001.phpt]
2023-03-25 18:15:42 +01:00
Niels Dossche
8e620b4ecb Fix GH-10928: PHP Build Failed - Test curl_version() basic functionality [ext/curl/tests/curl_version_basic_001.phpt]
It's possible that curl was compiled without SSL, and/or without libz
support. In the case of the issue reporter it was without libz support.
This causes the test to fail because we expect a non-empty string.
Fix it by using %S instead of %s to allow empty strings.

Closes GH-10930.
2023-03-25 18:15:20 +01: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
3d8107f74c
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  By-ref modification of typed and readonly props through ArrayIterator
2023-03-25 16:23:48 +01:00
Ilija Tovilo
9aaa5cd093
By-ref modification of typed and readonly props through ArrayIterator
Fixes GH-10844
Closes GH-10872
2023-03-25 16:14:19 +01:00
pakutoma
b721d0f71e Fix phpGH-10648: add check function pointer into mbfl_encoding
Previously, mbstring used the same logic for encoding validation as for
encoding conversion.

However, there are cases where we want to use different logic for validation
and conversion. For example, if a string ends up with missing input
required by the encoding, or if a character is input that is invalid
as an encoding but can be converted, the conversion should succeed and
the validation should fail.

To achieve this, a function pointer mb_check_fn has been added to
struct mbfl_encoding to implement the logic used for validation.
Also, added implementation of validation logic for UTF-7, UTF7-IMAP,
ISO-2022-JP and JIS.

(The same change has already been made to PHP 8.2 and 8.3; see
6fc8d014df. This commit is backporting the change to PHP 8.1.)
2023-03-25 09:52:10 +02:00
pakutoma
6fc8d014df Fix phpGH-10648: add check function pointer into mbfl_encoding
Previously, mbstring used the same logic for encoding validation as for
encoding conversion.

However, there are cases where we want to use different logic for validation
and conversion. For example, if a string ends up with missing input
required by the encoding, or if a character is input that is invalid
as an encoding but can be converted, the conversion should succeed and
the validation should fail.

To achieve this, a function pointer mb_check_fn has been added to
struct mbfl_encoding to implement the logic used for validation.
Also, added implementation of validation logic for UTF-7, UTF7-IMAP,
ISO-2022-JP and JIS.
2023-03-24 20:34:22 +02: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
8a2586228d Updated to version 2023.2 (2023b) 2023-03-24 10:10:18 +00:00
Derick Rethans
90f5b2b4ff Updated to version 2023.2 (2023b) 2023-03-24 10:10:17 +00:00
Derick Rethans
50ca489aa5 Merge branch 'PHP-8.1' into PHP-8.2 2023-03-23 14:49:18 +00: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
Derick Rethans
d9e89416f8 Updated to version 2023.1 (2023a) 2023-03-23 10:10:22 +00:00
Derick Rethans
8424b5caaa Updated to version 2023.1 (2023a) 2023-03-23 10:10:21 +00:00
Ilija Tovilo
c8f9adb44d
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  ext/curl: suppress -Wdeprecated-declarations in curl_arginfo.h
2023-03-22 20:58:25 +01:00
Max Kellermann
2646d76abc
ext/curl: suppress -Wdeprecated-declarations in curl_arginfo.h
Disable the warning before including curl_arginfo.h.

(Follow-up for https://github.com/php/php-src/pull/10531)
2023-03-22 20:57:41 +01:00
Ilija Tovilo
7c244f5539
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [skip ci] Add CONFLICTS file for curl tests
2023-03-21 19:17:36 +01:00
Ilija Tovilo
0842b13e5c
[skip ci] Add CONFLICTS file for curl tests 2023-03-21 19:17:06 +01: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
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
Arnaud Le Blanc
d87b670544 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Remove xfail from tests that do not fail anymore (#10871)
2023-03-17 18:13:31 +01:00