-
Problem report
-
Resolution: Unresolved
-
Major
-
None
-
6.0.24
-
None
-
Almalinux 8
Steps to reproduce:
- add a global regular expression that Expression is set to like "\q"
- test the expression, and it does not detect errors
- add a some log[] item that uses the global regex
Result:
A regex error occurs in Zabbix agent like:
5522:20231215:175524.212 active check "log[/var/log/messages,@wrong regex,,,skip]" is not supported: Invalid regular expression: unrecognized character follows \, position 1, flags:0x2408
Expected:
I think regex errors should be detected in regex test in Zabbix frontend.
Cause:
In PHP (< 8.0), BAD_ESCAPE_IS_LITERAL flag is set in preg_match() by default.
So wrong expressions like "\q" are not detected as errors.
Fix:
Removing BAD_ESCAPE_IS_LITERAL flag by adding "X" flag in reglar expression resolves this issue.
Here is a patch.
--- include/classes/validators/CRegexValidator.php.bak 2023-12-19 10:02:40.033397199 +0900 +++ include/classes/validators/CRegexValidator.php 2023-12-19 10:04:51.666395320 +0900 @@ -60,7 +60,7 @@ } }); - preg_match('/'.$value.'/', ''); + preg_match('/'.$value.'/X', ''); restore_error_handler();
Additional information:
In PHP 8.0, BAD_ESCAPE_IS_LITERAL flag is changed to not be used by default.
https://github.com/php/php-src/pull/4430
So this issue does not occur in RHEL 9 like system.