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

ExpandDeRefPromise: non-canonified class name is used as an argument of IsDefinedClass

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.7.0
    • Component/s: Evaluation
    • Labels:
      None

      Description

      It was introdused with b7fc59e85ebee26898f52bfff4d8aa5d4cc3c8fc
      "Short-circut evaluation of classes promises if class is already set"

      + // if this is a class promise, check if it is already set, if so, skip
      + if (strcmp("classes", pp->parent_promise_type->name) == 0)
      + {
      + if (IsDefinedClass(ctx, pcopy->promiser))
      + {

      here non-canonified class name is used with IsDefinedClass
      and this code could be a little bit annoying:

      root@sysdev:/etc/cfengine3# cf-agent -f test.cf
      2014-09-04T18:30:37+0400 error: /default/test/classes: Unable to parse class expression '/etc/debian_version'
      2014-09-04T18:30:37+0400 error: /default/test/classes: Unable to parse class expression '/etc/debian_version'
      2014-09-04T18:30:37+0400 error: /default/test/classes: Unable to parse class expression '/etc/debian_version'
      2014-09-04T18:30:37+0400 error: /default/test/classes: Unable to parse class expression '/etc/debian_version'
      2014-09-04T18:30:37+0400 error: /default/test/classes: Unable to parse class expression '/etc/debian_version'

      $ cat test.cf
      <pre>
      body common control {
      any::
      bundlesequence =>

      { "test" }

      ;
      }

      bundle agent test

      { vars: "path" string => "/etc/debian_version"; "path_c" string => canonify("$(path)"); classes: "$(path)" expression => fileexists("$(path)"); }

      </pre>

      Solution: use CanonifyName(pcopy->promiser) instead of pcopy->promiser

      Description: ExpandDeRefPromise: Canonify class name

      IsDefinedClass function used in ExpandDeRefPromise uses
      non-canonified promise name for comparison. This leads
      to multiple errors: 'Unable to parse class expression'.
      Introduced with commit:
      b7fc59e85ebee26898f52bfff4d8aa5d4cc3c8fc

      Fix: use CanonifyName(pcopy->promiser) instead of
      pcopy->promiser to compare.

      hmm.. am a newbie here and i don't know right way to send patches
      so i put it here, inline, sorry for inconvenience.

      <pre>
      — cfengine3-3.6.1.orig/libpromises/promises.c
      +++ cfengine3-3.6.1/libpromises/promises.c
      @@ -312,10 +312,10 @@ Promise *ExpandDeRefPromise(EvalContext
      // if this is a class promise, check if it is already set, if so, skip
      if (strcmp("classes", pp->parent_promise_type->name) == 0)
      {

      • if (IsDefinedClass(ctx, pcopy->promiser))
        + if (IsDefinedClass(ctx, CanonifyName(pcopy->promiser)))
        {
        Log(LOG_LEVEL_VERBOSE, "Skipping evaluation of classes promise as class '%s' is already set",
      • pcopy->promiser);
        + CanonifyName(pcopy->promiser));

      if (excluded)
      {
      </pre>

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              a10025 Volker Hilsheimer (Inactive)
              Reporter:
              git.user Alexander Fomichev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: