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

Support for valid regular expressions is broken in macros since 5.0.9

    XMLWordPrintable

Details

    • Problem report
    • Status: Closed
    • Trivial
    • Resolution: Won't fix
    • 5.0.9
    • None
    • Frontend (F)
    • None

    Description

      Using valid regular expression with properly escaped slash characters in macros results in error messages in the frontend.

      For example:

      "^\/$|^\/var$|^\/opt$|^\/tmp$|^\/home"
      "^\/(var|opt|tmp|home)$"
      "^\/$|^\/var$|^\/opt$|^\/tmp$|^\/home"
      

      etc.

      A screenshot of the dashboard widget attached.

      Running those regexps against the latest Zabbix code results in the same errors:

      <?php
      $regexps = array("^\/$|^\/var$|^\/opt$|^\/tmp$|^\/home", "^\/(var|opt|tmp|home)$", "^\/$|^\/var$|^\/opt$|^\/tmp$|^\/home", "^\/(var|opt|tmp|home)$", "^\/$|^\/var$|^\/opt$|^\/tmp$|^\/home", "^\/(var|opt|tmp|home)$");
      
      for ($i = 0; $i < count($regexps); $i++) {
              echo $regexps[$i]."\n";
              echo '/'.strtr(trim($regexps[$i], '/'), ['/' => '\\/']).'/'."\n";                       // what Zabbix does to regexp (ui/include/classes/macros/CMacrosResolverGeneral.php:1140)
              preg_match('/'.strtr(trim($regexps[$i], '/'), ['/' => '\\/']).'/', null);
      }
      ?>
      

      Output:

      ^\/$|^\/var$|^\/opt$|^\/tmp$|^\/home
      /^\\/$|^\\/var$|^\\/opt$|^\\/tmp$|^\\/home/
      PHP Warning:  preg_match(): Unknown modifier '$' in /root/test.php on line 7
      ^\/(var|opt|tmp|home)$
      /^\\/(var|opt|tmp|home)$/
      PHP Warning:  preg_match(): Unknown modifier '(' in /root/test.php on line 7
      ^\/$|^\/var$|^\/opt$|^\/tmp$|^\/home
      /^\\/$|^\\/var$|^\\/opt$|^\\/tmp$|^\\/home/
      PHP Warning:  preg_match(): Unknown modifier '$' in /root/test.php on line 7
      ^\/(var|opt|tmp|home)$
      /^\\/(var|opt|tmp|home)$/
      PHP Warning:  preg_match(): Unknown modifier '(' in /root/test.php on line 7
      ^\/$|^\/var$|^\/opt$|^\/tmp$|^\/home
      /^\\/$|^\\/var$|^\\/opt$|^\\/tmp$|^\\/home/
      PHP Warning:  preg_match(): Unknown modifier '$' in /root/test.php on line 7
      ^\/(var|opt|tmp|home)$
      /^\\/(var|opt|tmp|home)$/
      PHP Warning:  preg_match(): Unknown modifier '(' in /root/test.php on line 7
      

      This is because since ZBX-18209 Zabbix in the code automatically puts backslashes in front of slashes and therefore in properly written regular expression the slash is treated as the termination of the regular expression and the rest of the regular expression is supposed to be the modifiers.

      Probably ZBX-18209 should be reverted.

      Kind regards,
      Sergey

      Attachments

        Activity

          People

            zabbix.dev Zabbix Development Team
            ssimonenko Sergey Simonenko
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: