[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6

From: Date: Sat, 14 Nov 2026 16:11:50 +0000
Subject: [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143705@lists.php.net to get a copy of this message
Author: Jorg Sowa (jorgsowa) Date: 2026-11-14T17:03:57+01:00 Commit: https://github.com/php/php-src/commit/6ef88b00cc36da85485bb941cc5c81aa3893f377 Raw diff: https://github.com/php/php-src/commit/6ef88b00cc36da85485bb941cc5c81aa3893f377.diff Merge branch 'PHP-8.5' into PHP-8.6 Changed paths: A ext/pcre/tests/preg_inline_utf_backslash_c.phpt M NEWS M ext/pcre/php_pcre.c Diff: diff --git a/NEWS b/NEWS index 1fd03816816e..5a908d5b6d53 100644 --- a/NEWS +++ b/NEWS @@ -109,6 +109,10 @@ PHP NEWS . Fixed stack buffer overflow with long connection user names, passwords, charsets, or roles. (Ilia Alshanetsky) +- PCRE: + . Fixed \C being allowed in patterns enabling UTF mode with (*UTF) instead + of the u modifier. (Jorg Sowa) + - SOAP: . Fixed bug GH-25267 (NULL dereference in to_xml_any() with integer key). (lazerg) diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index fd239eb887fa..be85c1aec0f3 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -580,6 +580,8 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, bo uint32_t coptions = 0; #endif uint32_t eoptions = 0; + uint32_t all_options; + uint32_t has_backslash_c; PCRE2_UCHAR error[128]; PCRE2_SIZE erroffset; int errnumber; @@ -776,6 +778,22 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, bo /* Compile pattern and display a warning if compilation failed. */ re = pcre2_compile((PCRE2_SPTR)pattern, pattern_len, coptions, &errnumber, &erroffset, cctx); + /* In-pattern verbs such as (*UTF) can enable PCRE2_UTF, in which \C is unsafe. */ + if (re != NULL && !(coptions & PCRE2_NEVER_BACKSLASH_C) + && pcre2_pattern_info(re, PCRE2_INFO_HASBACKSLASHC, &has_backslash_c) >= 0 + && has_backslash_c + && pcre2_pattern_info(re, PCRE2_INFO_ALLOPTIONS, &all_options) >= 0 + && (all_options & PCRE2_UTF)) { + pcre2_code_free(re); + if (key != regex) { + zend_string_release_ex(key, 0); + } + php_error_docref(NULL, E_WARNING, "Compilation failed: using \\C is incompatible with UTF-8 mode"); + pcre_handle_exec_error(PCRE2_ERROR_INTERNAL); + efree(pattern); + return NULL; + } + if (re == NULL) { if (key != regex) { zend_string_release_ex(key, 0); diff --git a/ext/pcre/tests/preg_inline_utf_backslash_c.phpt b/ext/pcre/tests/preg_inline_utf_backslash_c.phpt new file mode 100644 index 000000000000..bbfcc7f53575 --- /dev/null +++ b/ext/pcre/tests/preg_inline_utf_backslash_c.phpt @@ -0,0 +1,41 @@ +--TEST-- +In-pattern (*UTF) forbids \C like the /u modifier +--FILE-- +<?php +$patterns = [ + '/(*UTF)\C/', + '/(*UTF8)a\C/', + '/(*LIMIT_MATCH=100)(*UTF)a\C/', + '/\C/u', +]; +foreach ($patterns as $pattern) { + var_dump(preg_match($pattern, "a\u{E4}")); +} + +// GH-21134 reproducer using (*UTF) instead of /u +var_dump(preg_match_all("/(*UTF)(.*)\\C/", "\u{E0}", $m), $m); + +// \C is still allowed outside UTF mode, and an escaped backslash is not \C +var_dump(preg_match('/a\C/', "a\u{E4}", $m), bin2hex($m[0])); +var_dump(preg_match('/(*UTF)\\\\C/', 'x\C')); +?> +--EXPECTF-- + +Warning: preg_match(): Compilation failed: using \C is incompatible with UTF-8 mode in %s on line %d +bool(false) + +Warning: preg_match(): Compilation failed: using \C is incompatible with UTF-8 mode in %s on line %d +bool(false) + +Warning: preg_match(): Compilation failed: using \C is incompatible with UTF-8 mode in %s on line %d +bool(false) + +Warning: preg_match(): Compilation failed: using \C is incompatible with the 'u' modifier at offset 2 in %s on line %d +bool(false) + +Warning: preg_match_all(): Compilation failed: using \C is incompatible with UTF-8 mode in %s on line %d +bool(false) +NULL +int(1) +string(4) "61c3" +int(1)

« previous php.cvs (#143705) next »