Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-2903

Variablesmatching() treats argument as both regex and string

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: Low
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.12.1
    • Component/s: None
    • Labels:
      None

      Description

      This "feature" is not documented, but allows crazy stuff.

      Policy:

      root@dev core $ cat vars.cf
      bundle agent de
      {
          vars:
              "d" string => "OK";
              "de" string => "OK";
              "d[e]" string => "OK";
              "dee" string => "OK";
              "de[e]" string => "OK";
              "d[e][e]" string => "OK";
              "deee" string => "OK";
              "dee[e]" string => "OK";
              "de[e][e]" string => "OK";
              "d[e][e][e]" string => "OK";
      
              "prefix" string => "default:de.";
              "regex" string => "d[[e\[\]]{0,20}]";
              "varname" string => "$(regex)";
              "arg" string => "$(prefix)$(regex)";
              "$(varname)" slist => variablesmatching("$(arg)");
          reports:
              "The variable name includes a regex: '$(varname)'";
              "Variables matching regex '$(arg)': '$($(varname))'";
      }
      
      bundle agent main
      {
          methods:
              "any" usebundle => de();
      }
      root@dev core $
      

      Output:

      root@dev core $ /var/cfengine/bin/cf-agent vars.cf -K
      R: The variable name includes a regex: 'd[[e\[\]]{0,20}]'
      R: Variables matching regex 'default:de.d[[e\[\]]{0,20}]': 'default:de.de[e]'
      R: Variables matching regex 'default:de.d[[e\[\]]{0,20}]': 'default:de.d[e][e][e]'
      R: Variables matching regex 'default:de.d[[e\[\]]{0,20}]': 'default:de.dee[e]'
      R: Variables matching regex 'default:de.d[[e\[\]]{0,20}]': 'default:de.d[e]'
      R: Variables matching regex 'default:de.d[[e\[\]]{0,20}]': 'default:de.de[e][e]'
      R: Variables matching regex 'default:de.d[[e\[\]]{0,20}]': 'default:de.d[e][e]'
      R: Variables matching regex 'default:de.d[[e\[\]]{0,20}]': 'default:de.d[[e\[\]]{0,20}]'
      root@dev core $
      

      Note that the regex in the variable matches itself (because a string comparison returns true) and other variables, because it does regex match if string comparison is false.
      It is a very pathological case, but it means that sometimes variablesmatching will match stuff, not because it's a regex match, but because it's a string match.

      Acceptance criteria:

      • Remove string comparison so the argument is only treated as a regex or update the documentation

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                olehermanse Ole Herman Schumacher Elgesem
                Reporter:
                olehermanse Ole Herman Schumacher Elgesem
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Summary Panel