-
Notifications
You must be signed in to change notification settings - Fork 8k
Forbid \C in UTF-8 patterns #21139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: PHP-8.4
Are you sure you want to change the base?
Forbid \C in UTF-8 patterns #21139
Conversation
| coptions |= PCRE2_UCP; | ||
| #endif | ||
| /* The \C escape sequence is unsafe in PCRE2_UTF mode */ | ||
| coptions |= PCRE2_NEVER_BACKSLASH_C; |
There was a problem hiding this comment.
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 ?
| } | ||
| 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)); |
There was a problem hiding this comment.
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.
|
I know enough pcre2 to see it s LGTM but cc @ndossche just in case :) |
| 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); |
There was a problem hiding this comment.
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):
| 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); |
There was a problem hiding this comment.
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.
|
Since it can otherwise induce some potentially unsafe behaviour, I think 8.4 is reasonable. |
Possible fix for GH-21134.
\Cresults in undefined, potentially unsafe behavior in UTF-8 mode, so error out in case the escape sequence is used in UTF-8 mode.