Commit graph

1261 commits

Author SHA1 Message Date
Remi Collet
5de019d9bd
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Relax test expectation for pcre2lib 10.45 Using e92848789a
2025-03-13 07:46:55 +01:00
Remi Collet
69480be12a
Relax test expectation for pcre2lib 10.45 Using e92848789a
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2025-03-13 07:46:18 +01:00
Niels Dossche
dc27acddd6
Fix GH-17122: memory leak in regex
Because the subpattern names are persistent, and the fact that the
symbol table destruction is skipped when using fast_shutdown,
this means the refcounts will not be updated for the destruction of
the arrays that hold the subpattern name keys.
To solve this, detect this situation and duplicate the strings.

Closes GH-17132.
2025-01-06 20:11:36 +01:00
Niels Dossche
5839fc5dd9
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16184: UBSan address overflowed in ext/pcre/php_pcre.c
2024-10-03 21:12:42 +02:00
Niels Dossche
ddc7a6b1fc
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16184: UBSan address overflowed in ext/pcre/php_pcre.c
2024-10-03 21:11:25 +02:00
Niels Dossche
c4bb07552e
Fix GH-16184: UBSan address overflowed in ext/pcre/php_pcre.c
libpcre2 can return the special value -1 for a non-match.
In this case we get pointer overflow, although it doesn't matter in
practice because the pointer will be in bounds and the copy length will
be 0. Still, we should fix the UBSAN warning.

Closes GH-16205.
2024-10-03 21:10:57 +02:00
David Carlier
f5d4781ee0
Merge branch 'PHP-8.3' into PHP-8.4 2024-10-03 12:48:46 +01:00
David Carlier
1aeb70f83c
Merge branch 'PHP-8.2' into PHP-8.3 2024-10-03 12:48:34 +01:00
David Carlier
f453d1ae2a
Fix GH-16189: underflow on preg_match/preg_match_all start_offset.
close GH-16191
2024-10-03 12:48:13 +01:00
Ilija Tovilo
ffb440550c
Use APPLY_STOP in pcre_clean_cache() (GH-15839)
Once num_clean has reached 0, we never remove any more elements anyway.

Closes GH-15839
2024-09-12 22:32:23 +02:00
Niels Dossche
ded8fb79bd
Fix UAF issues with PCRE after request shutdown
There are two related issues, each tested.

First problem:
What happens is that on the CLI SAPI we have a per-request pcre cache,
and on there the request shutdown for the pcre module happens prior to
the remaining live object destruction. So when the SPL object wants to
clean up the regular expression object it gets a use-after-free.

Second problem:
Very similarly, the non-persistent resources are destroyed after request
shutdown, so on the CLI SAPI the pcre request cache is already gone, but
if a userspace stream references a regex in the pcre cache, this breaks.

Two things that come immediately to mind:
  -  We could fix it by no longer treating the CLI SAPI special and just use
     the same lifecycle as the module. This simplifies the pcre module code
     a bit too. I wonder why we even have the separation in the first place.
     The downside here is that we're using more the system allocator
     than Zend's allocator for cache entries.
  -  We could modify the shutdown code to not remove regular expressions
     with a refcount>0 and modify php_pcre_pce_decref code such that it
     becomes php_pcre_pce_decref's job to clean up when the refcount
     becomes 0 during shutdown. However, this gets nasty quickly.

I chose the first solution here as it should be reliable and simple.

Closes GH-15064.
2024-09-11 18:49:19 +02:00
Peter Kokot
80825672d1
Autotools: Fix external PCRE JIT check (#15430)
If using a custom PCRE library installation, also CFLAGS and LIBS
variables need to be adapted for the JIT check to be able to find it.
2024-08-16 19:21:13 +02:00
Peter Kokot
d6a75e19d1
Sync preprocessor macros help texts (#15218)
This partially syncs help texts a bit further for:
- ext/ffi
- ext/ldap
- ext/opcache
- ext/pcre
- ext/pdo_mysql
- ext/readline
- ext/standard
2024-08-04 12:52:16 +02:00
Peter Kokot
40cf2e1279
Autotools: Normalize pcre sources (#15085) 2024-07-24 01:53:51 +02:00
Peter Kokot
9f74329bb6
Merge branch 'PHP-8.3'
* PHP-8.3:
  Append -Wno-implicit-fallthrough flag conditionally (#13331)
2024-07-22 07:02:25 +02:00
Peter Kokot
f702437cad
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Append -Wno-implicit-fallthrough flag conditionally (#13331)
2024-07-22 06:58:01 +02:00
Peter Kokot
d20d11375f
Append -Wno-implicit-fallthrough flag conditionally (#13331)
Older GCC versions (< 7.0) don't support the -Wno-implicit-fallthrough
compiler flag. This adds the flag conditionally in case some other
compiler will run into same issue.

Fixes GH-13330
2024-07-22 06:57:04 +02:00
Peter Kokot
68ae477796
Autotools: Quote M4 arguments (#15033)
- PHP_ADD_INCLUDE
- PHP_EVAL_INCLINE
- PHP_EVAL_LIBLINE
2024-07-20 07:21:44 +02:00
Peter Kokot
0e2e8e0f13
Autotools: Quote all PHP_ADD_BUILD_DIR arguments (#14947)
- All arguments quoted for consistency
- m4_normalize used where list of directories becomes a bit simpler to
  read and see the diff
2024-07-14 16:58:43 +02:00
Peter Kokot
063213b1ae
Autotools: Refactor PCRE JIT checks (#14781)
- Check message moved to 2nd argument of PHP_ARG_WITH
- AH_TEMPLATE takes care of help message defined on one place for both
  defines
- AS_VAR_IF used and CS sycned a bit
- Cache variables renamed to php_cv_*
- Redundant AC_CANONICAL_HOST call removed. The host_cpu is set together
  with a triplet in PHP_CANONICAL_HOST_TARGET
- Over-quoted arguments reduced
2024-07-03 14:10:29 +02:00
Peter Kokot
9caad3745d
Autotools: Refactor Valgrind support (#14736)
When Valgrind is enabled and not found on the system, default error can
be thrown by PKG_CHECK_MODULES instead of writing a manual error step.
- This uses less redundant variables and has synced CS.
- AS_VAR_IF used instead of raw shell ifs
- Added some basic help descriptions for macro definitions
2024-07-01 00:29:44 +02:00
Ayesh Karunaratne
d8795a3503
ext/pcre: update Config to match upstream (#14509)
In GH-14498, we updated pcre2lib to v10.44. However, it missed syncing the config,
that changes upstream `MAX_NAME_SIZE` from 32 to 128.

Ref: [1](ced3b0f06f (diff-91c5b46dc84a94604a4e4d0caed9bf85590a2eddbb12d2e8dc80badf324a9dfb)), [2](6c670c780a)
2024-06-08 21:34:18 +02:00
Ayesh Karunaratne
d1f14a4609
ext/pcre: update to PCRE2 v10.44 (#14498)
Previously: GH-13413.

This version also contains a fix with `preg_match('\X')`, so that it
can correctly detect grapheme clusters (PCRE2Project/pcre2#410).
This is useful to correctly [polyfill the new `grapheme_str_split`
function](https://php.watch/versions/8.4/grapheme_str_split#polyfill).

Diff: pcre2lib [v10.43..v10.44](https://github.com/PCRE2Project/pcre2/compare/pcre2-10.43...pcre2-10.44)
2024-06-08 13:03:31 +02:00
Niels Dossche
259744148e
Cache pcre subpattern table (#14424)
Recreating this over and over is pointless, cache this as well.
Fixes GH-14423.
2024-06-03 21:15:26 +02:00
Niels Dossche
315f2059b7
Remove dead check in pcre
This isn't reachable since ab32d36, because since then the library
itself checks this condition during compilation. The compilation failure
that results of it makes this code not reachable.

This is split off of GH-14424.
2024-06-03 19:58:22 +02:00
Gina Peter Banyard
25a5146180
Clean-up unused headers (#14365)
* ext/mbstring.c: clean-up headers and include intrinsics
2024-06-01 17:12:42 +01:00
Peter Kokot
e45d2d6046
Sync HAVE_BUNDLED_PCRE #if/ifdef/defined (#14354)
Follow up of GH-5526 (-Wundef)
2024-05-29 07:53:36 +02:00
Ilija Tovilo
1c30c5e707
Print location on class redeclaration
Fixes GH-13950
Closes GH-13999
2024-04-30 14:34:43 +02:00
Niels Dossche
d0e15c8502
Fix external pcre2 build (#13662)
PCRE2_EXTRA_CASELESS_RESTRICT is only available as of pcre2 10.43.
Note: no check is necessary for pcre2_set_compile_extra_options because
it is available since pcre2 10.30, which is the minimum version PHP
requires.
2024-03-10 13:15:15 +01:00
Peter Kokot
2f6a210755
Use memmove() unconditionally in the code (#13647)
The memmove() function is C99 standard function [1] and check was left for
the PCRE2 bundled library. It can be simplified by passing the compile
option instead of checking always available function on current systems.
External PCRE2 library on the system doesn't need this.

[1]: https://port70.net/~nsz/c/c99/n1256.html#7.21.2.2
2024-03-09 20:30:08 +01:00
Ayesh Karunaratne
7b23470666
ext/pcre: Add "/r" modifier (#13583)
Adds support for "Caseless restricted" matching added in PCRE2lib
10.43 with the "r" modifier.

This is `PCRE2_EXTRA_CASELESS_RESTRICT` in PCRE2. This is an "extra"
option, which means it is not possible to pass this option as
pcre2_compile() function parameter.

This option is passed in a pcre2_set_compile_extra_options() call.
Previously, these extra options are set at php_pcre_init_pcre2(),
but after this change, it is possible to customize the options
by adding bits to `eoptions` in pcre_get_compiled_regex_cache_ex().

The tests for this change are ported from upstream test suite[^1].

[^1]: c13d54f658 (diff-8c8312e4eb2d35bb16485404b7b5cc0eaef0bca1aa95ff5febf6a1890048305c)
2024-03-05 20:51:04 +01:00
Máté Kocsis
f2e199e878
Implement "support doc comments for internal classes and functions" (#13266)
Fixes #13130
2024-02-25 08:41:31 +01:00
Peter Kokot
0ddc3a23fa [skip ci] Fix Intel CET check in ext/pcre
This adds test program body `int main(void) { return 0; }` and fixes the
configure step with cache enabled (`configure -C`).
2024-02-19 14:25:40 +01:00
Máté Kocsis
10957e498c
Do not generate frameless info items when func info generation is disabled
While here, I fixed newlines around arginfo and function entry generation. Previously, newlines were repeated.
2024-02-18 11:39:00 +01:00
Niels Dossche
ae5beff61b
Upgrade bundled pcre2lib to 10.43 (#13413) 2024-02-17 14:15:04 +01:00
Ilija Tovilo
631bc81607
Implement stackless internal function calls
Co-authored-by: Dmitry Stogov <dmitry@zend.com>

Closes GH-12461
2024-02-06 17:42:28 +01:00
Jorg Adam Sowa
73722df439
Improve preg_* functions warnings for NUL byte (#13068)
* Improve error messages for preg_ functions
* Adjusted tests and fixed formatting
* Removed unnecessary strings from preg_* tests
* Removed ZPP tests
2024-01-07 13:40:54 +00:00
David CARLIER
952ffbfe50
macOs CI update. (#12998)
macOs CI update.

since sonoma (14) had been released since few months, we could afford to
upgrade to its previous release.
2023-12-22 15:24:53 +00:00
Cristian Rodríguez
927adfb1a6
Use a single version of mempcpy(3) (#12257)
While __php_mempcpy is only used by ext/standard/crypt_sha*, the
mempcpy "pattern" is used everywhere.

This commit removes __php_mempcpy, adds zend_mempcpy and transforms
open-coded parts into function calls.
2023-12-20 15:16:32 +00:00
Ilija Tovilo
be46545ee0
Fix pcre out-of-bounds when using closing symbols as opening delimiter (#12946)
Apparently we support using closing symbols )]}> as opening and closing
delimiters.

Fixes oss-fuzz #65021
2023-12-12 21:58:34 +01:00
Niels Dossche
642e11140c
Minor pcre optimizations (#12923)
* Update signature of pcre API

This changes the variables that are bools to actually be bools instead
of ints, which allows some additional optimization by the compiler (e.g.
removing some ternaries and move extensions).

It also gets rid of the use_flags argument because that's just the same
as flags == 0. This reduces the call frame.

* Use zend_string_release_ex where possible

* Remove duplicate symbols from strchr

* Avoid useless value conversions

* Use a raw HashTable* instead of a zval

* Move condition

* Make for loop cheaper by reusing a recently used value as start iteration index

* Remove useless condition

This can't be true if the second condition is true because it would
require the string to occupy the entire address space.

* Upgrading + remark
2023-12-11 19:43:26 +01:00
Michael Voříšek
8d98f7202a
Use ZSTR_IS_VALID_UTF8 macro where possible (#12869) 2023-12-05 05:24:11 +00:00
Niels Dossche
490b80858d Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-12633: sqlite3_defensive.phpt fails with sqlite 3.44.0
  Fix GH-12628: The gh11374 test fails on Alpinelinux
2023-11-10 00:13:15 +01:00
Niels Dossche
e6fef2944b Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-12633: sqlite3_defensive.phpt fails with sqlite 3.44.0
  Fix GH-12628: The gh11374 test fails on Alpinelinux
2023-11-10 00:12:47 +01:00
Niels Dossche
fbda6b50a3 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-12633: sqlite3_defensive.phpt fails with sqlite 3.44.0
  Fix GH-12628: The gh11374 test fails on Alpinelinux
2023-11-10 00:08:09 +01:00
Niels Dossche
78fba9cb80 Fix GH-12628: The gh11374 test fails on Alpinelinux
Closes GH-12636.
2023-11-10 00:01:22 +01:00
Niels Dossche
d97ce2f086 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-11374: Different preg_match result with -d pcre.jit=0
2023-10-27 17:48:04 +02:00
Niels Dossche
e7cbcfda14 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-11374: Different preg_match result with -d pcre.jit=0
2023-10-27 17:45:44 +02:00
Niels Dossche
1ea8a10ca8 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11374: Different preg_match result with -d pcre.jit=0
2023-10-27 17:44:56 +02:00
Michael Voříšek
83a505e85f Fix GH-11374: Different preg_match result with -d pcre.jit=0
This is a backport of https://github.com/PCRE2Project/pcre2/pull/300.

Closes GH-12439.
2023-10-27 17:43:33 +02:00