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

Potentially non-unique class setting in set_variable_values* stdlib bundles

    XMLWordPrintable

    Details

      Description

      In (for example) the set_variable_values_ini edit_line bundle in stdlib/files.cf there is an edit_field promise done for a variable in a file. This check sets a class if the edit_field is successfull, ie, if the variable is found to exist and can be set to the right value. Otherwise the class is not set and an insert_lines promise is triggered by ifvarclass.

      If the same LHS variable name occurs again, either in another bundle call or another section of the ini file, the class set by if_ok is no longer unique. Because it is set by a classes body, it is global and results in the ifvarclass statement being untrue regardless of the actual outcome of the promise checking for the existence of the variable string in the file. Therefore the 2nd occurrence of the same variable anywhere won't be properly inserted even if necessary.

      I was able to resolve the issue by making the class more unique as in these code snips (this is not the entire bundle). Unless the behaviour of the classes body has changed this would presumably effect any version of cfengine.

      <pre>
      bundle edit_line set_variable_values_ini(tab, sectionName) {

      vars:

      "index" slist => getindices("$(tab)[$(sectionName)]");

      1. ==> added $(tab)$(sectionName)
        "cindex[$(index)]" string => canonify("$(tab)$(sectionName)$(index)");

      field_edits:

      1. match a line starting like the key something
        "$(index)\s*=.*"
        edit_field => col("=","2","$($(tab)[$(sectionName)][$(index)])","set"),
        select_region => INI_section("$(sectionName)"),
      2. ==> before this class was not necessarily unique
        classes => if_ok("set_variable_values_ini_not_$(cindex[$(index)])"),
        ifvarclass => "edit_$(cindex[$(index)])";

      insert_lines:

      "$(index)=$($(tab)[$(sectionName)][$(index)])"
      select_region => INI_section("$(sectionName)"),
      ifvarclass => "!$set_variable_values_ini_not_$(cindex[$(index)]).edit_$(cindex[$(index)])";
      }
      </pre>

      This issue seems like it would effect other similar edit_lines bundles but could be resolved with similar changes.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                a10042 Nick Anderson
                Reporter:
                bmeekhof Ben Meekhof
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Summary Panel