Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-23865

regex test in frontend does not detect invalid expressions

XMLWordPrintable

    • Icon: Problem report Problem report
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 6.0.24
    • Frontend (F)
    • None
    • Almalinux 8

      Steps to reproduce:

      1. add a global regular expression that Expression is set to like "\q"
      2. test the expression, and it does not detect errors
      3. 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.

       

       

        1. regexp1.png
          11 kB
          Kento Takahashi
        2. regexp2.png
          15 kB
          Kento Takahashi
        3. with_patch.png
          18 kB
          Kento Takahashi

            zabbix.dev Zabbix Development Team
            kento.takahashi Kento Takahashi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: