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

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

      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

            zabbix.dev Zabbix Development Team
            ssimonenko Sergey Simonenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: