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

Potentially non-unique class setting in set_variable_values* stdlib bundles




      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.

      bundle edit_line set_variable_values_ini(tab, sectionName) {


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

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


      1. match a line starting like the key something
        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)])";


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

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


          Issue Links



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


                • Created:

                  Summary Panel