Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ext/pcre/php_pcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, bo
#ifdef PCRE2_UCP
coptions |= PCRE2_UCP;
#endif
/* The \C escape sequence is unsafe in PCRE2_UTF mode */
coptions |= PCRE2_NEVER_BACKSLASH_C;
Copy link
Member

@devnexen devnexen Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would need to document it somehow (UPGRADING ?) wdyt ?

break;
case 'J': coptions |= PCRE2_DUPNAMES; break;

Expand Down Expand Up @@ -787,7 +789,11 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, bo
if (key != regex) {
zend_string_release_ex(key, 0);
}
pcre2_get_error_message(errnumber, error, sizeof(error));
if (errnumber == PCRE2_ERROR_BACKSLASH_C_CALLER_DISABLED) {
strlcpy((char*)error, "using \\C is incompatible with the 'u' modifier", sizeof(error));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the default message is a bit vague in this context, makes sense.

} else {
pcre2_get_error_message(errnumber, error, sizeof(error));
}
php_error_docref(NULL,E_WARNING, "Compilation failed: %s at offset %zu", error, erroffset);
Comment on lines +792 to 797
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the strlcpy call is ugly, but I won't object. Why not smth like this (and possibly rename error to error_buf):

Suggested change
if (errnumber == PCRE2_ERROR_BACKSLASH_C_CALLER_DISABLED) {
strlcpy((char*)error, "using \\C is incompatible with the 'u' modifier", sizeof(error));
} else {
pcre2_get_error_message(errnumber, error, sizeof(error));
}
php_error_docref(NULL,E_WARNING, "Compilation failed: %s at offset %zu", error, erroffset);
const char *err_msg = (const char *) error;
if (errnumber == PCRE2_ERROR_BACKSLASH_C_CALLER_DISABLED) {
err_msg = "using \\C is incompatible with the 'u' modifier";
} else {
pcre2_get_error_message(errnumber, error, sizeof(error));
}
php_error_docref(NULL,E_WARNING, "Compilation failed: %s at offset %zu", err_msg, erroffset);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on that, I was surprised to see pcre2 provides a strcpy-like only for their own buffer type.

pcre_handle_exec_error(PCRE2_ERROR_INTERNAL);
efree(pattern);
Expand Down
15 changes: 15 additions & 0 deletions ext/pcre/tests/gh21134.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
GH-21134: ASan negative-size-param in preg_match_all() with \C + UTF-8 multibyte input
--CREDITS--
vi3tL0u1s
--FILE--
<?php

$r = preg_match_all("/(.*)\\C/u", "à", $m);
var_dump($r, $m);

?>
--EXPECTF--
Warning: preg_match_all(): Compilation failed: using \C is incompatible with the 'u' modifier at offset 6 in %s on line %d
bool(false)
NULL
Loading