tliron / puccini

Cloud topology management and deployment tools based on TOSCA
https://puccini.cloud
Apache License 2.0
88 stars 20 forks source link

Segmentation fault when parsing output mapping in relationship notification #120

Closed Shishqa closed 1 year ago

Shishqa commented 1 year ago

The issue

When I pass a template with incorrect output mapping in relationship notification, I get a segmentation fault.

Example of incorrect mapping:

relationship_types:

  CustomDependsOn:
    derived_from: tosca.relationships.DependsOn
    interfaces:
      Configure:
        notifications:
          test:
            implementation: playbook.yaml
            outputs:
              var: [ SELF, bar ]

Reproducing

Here is the faulty example:

tosca_definitions_version: tosca_simple_yaml_1_3

relationship_types:

  CustomDependsOn:
    derived_from: tosca.relationships.DependsOn
    interfaces:
      Configure:
        notifications:
          test:
            implementation: playbook.yaml
            outputs:
              var: [ SELF, bar ]

topology_template:

  node_templates:

    server_2:
      type: tosca:Compute
      requirements:
        - dependency:
            node: server_1
            relationship:
              type: CustomDependsOn

    server_1:
      type: tosca:Compute

Paste this template into https://web.puccini.cloud/

The stack trace is:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x0 addr=0x0 pc=0x0]

goroutine 1 [running]:
github.com/tliron/puccini/tosca/grammars/tosca_v2_0.(*NodeTemplate).GetContext(0x0)
    <autogenerated>:1 +0x1
    github.com/tliron/puccini/tosca.GetContext({0x154a60, 0x0})
    /Depot/Projects/RedHat/puccini/tosca/context.go:26 +0x6
    github.com/tliron/puccini/tosca.(*Context).ReportReferenceNotFound(0x165ae70, {0x1f9df1, 0x9}, {0x154a60, 0x0})
    /Depot/Projects/RedHat/puccini/tosca/report.go:175 +0xf
    github.com/tliron/puccini/tosca/grammars/tosca_v2_0.(*OutputMapping).setRelationship(0x15257c0, 0x1525980)
    /Depot/Projects/RedHat/puccini/tosca/grammars/tosca_v2_0/output-mapping.go:132 +0x12
    github.com/tliron/puccini/tosca/grammars/tosca_v2_0.(*OutputMapping).RenderForRelationship(0x15257c0, 0x1525980)
    /Depot/Projects/RedHat/puccini/tosca/grammars/tosca_v2_0/output-mapping.go:85 +0xd
    github.com/tliron/puccini/tosca/grammars/tosca_v2_0.OutputMappings.RenderForRelationship(0x17b0d80, 0x1525980)
    /Depot/Projects/RedHat/puccini/tosca/grammars/tosca_v2_0/output-mapping.go:195 +0x6
    github.com/tliron/puccini/tosca/grammars/tosca_v2_0.NotificationAssignments.RenderForRelationship(0x17b04b0, 0x1525980, 0x15ca5d0, 0x165aa50)
    /Depot/Projects/RedHat/puccini/tosca/grammars/tosca_v2_0/notification-assignment.go:103 +0x9
    github.com/tliron/puccini/tosca/grammars/tosca_v2_0.(*InterfaceAssignment).RenderForRelationship(0x17b04e0, 0x1525980, 0x15a1860)
    /Depot/Projects/RedHat/puccini/tosca/grammars/tosca_v2_0/interface-assignment.go:83 +0x11
    github.com/tliron/puccini/tosca/grammars/tosca_v2_0.InterfaceAssignments.RenderForRelationship(0x15cadb0, 0x1525980, 0x15ca420, 0x15e78c0)
    /Depot/Projects/RedHat/puccini/tosca/grammars/tosca_v2_0/interface-assignment.go:139 +0xc
    github.com/tliron/puccini/tosca/grammars/tosca_v2_0.(*RelationshipAssignment).Render(0x1525980, 0x172c900)
    /Depot/Projects/RedHat/puccini/tosca/grammars/tosca_v2_0/relationship-assignment.go:94 +0x47
    github.com/tliron/puccini/tosca/grammars/tosca_v2_0.(*RequirementAssignments).Render(0x15c6f58, 0x172cc00, 0x1c87290)
    /Depot/Projects/RedHat/puccini/tosca/grammars/tosca_v2_0/requirement-assignment.go:180 +0x8d
    github.com/tliron/puccini/tosca/grammars/tosca_v2_0.(*NodeTemplate).render(0x15c6f00)
    /Depot/Projects/RedHat/puccini/tosca/grammars/tosca_v2_0/node-template.go:83 +0x1e
    sync.(*Once).doSlow(0x140b208, 0x146f4e0)
    /Depot/Applications/go/src/sync/once.go:68 +0x9
    sync.(*Once).Do(0x140b208, 0x146f4e0)
    /Depot/Applications/go/src/sync/once.go:59 +0x6
    github.com/tliron/puccini/tosca/grammars/tosca_v2_0.(*NodeTemplate).Render(0x15c6f00)
    /Depot/Projects/RedHat/puccini/tosca/grammars/tosca_v2_0/node-template.go:70 +0x6
    github.com/tliron/puccini/tosca.Render(...)
    /Depot/Projects/RedHat/puccini/tosca/entity.go:151
    github.com/tliron/puccini/tosca/parser.(*ServiceContext).Render.func1({0x154a60, 0x15c6f00})
    /Depot/Projects/RedHat/puccini/tosca/parser/phase5-rendering.go:14 +0x8
    github.com/tliron/kutil/reflection.EntityWork.TraverseEntities.func1({0x154a60, 0x15c6f00})
    /home/emblemparade/go/pkg/mod/github.com/tliron/kutil@v0.1.52/reflection/traverse.go:130 +0xf
    github.com/tliron/kutil/reflection.TraverseEntities({0x154a60, 0x15c6f00}, 0x0, 0x146fb00)
    /home/emblemparade/go/pkg/mod/github.com/tliron/kutil@v0.1.52/reflection/traverse.go:21 +0x18
    github.com/tliron/kutil/reflection.TraverseEntities({0x15e3c0, 0x1469b90}, 0x0, 0x146fb00)
    /home/emblemparade/go/pkg/mod/github.com/tliron/kutil@v0.1.52/reflection/traverse.go:81 +0xd3
    github.com/tliron/kutil/reflection.TraverseEntities({0x13de40, 0x15b7850}, 0x0, 0x146fb00)
    /home/emblemparade/go/pkg/mod/github.com/tliron/kutil@v0.1.52/reflection/traverse.go:64 +0x8e
    github.com/tliron/kutil/reflection.EntityWork.TraverseEntities(0x1574ff0, {0x13de40, 0x15b7850}, 0x146fb48)
    /home/emblemparade/go/pkg/mod/github.com/tliron/kutil@v0.1.52/reflection/traverse.go:128 +0x2
    github.com/tliron/puccini/tosca/parser.(*ServiceContext).Render(0x1598fc0)
    /Depot/Projects/RedHat/puccini/tosca/parser/phase5-rendering.go:13 +0x11
    github.com/tliron/puccini/puccini-tosca/commands.Parse({0x0, 0x0})
    /Depot/Projects/RedHat/puccini/puccini-tosca/commands/parse.go:164 +0x91
    github.com/tliron/puccini/puccini-tosca/commands.Compile({0x0, 0x0})
    /Depot/Projects/RedHat/puccini/puccini-tosca/commands/compile.go:48 +0x2
    github.com/tliron/puccini/puccini-tosca/commands.glob..func1(0x1022820, {0x15369e0, 0x0, 0x2})
    /Depot/Projects/RedHat/puccini/puccini-tosca/commands/compile.go:42 +0x5
    github.com/spf13/cobra.(*Command).execute(0x1022820, {0x15369c0, 0x2, 0x2})
    /home/emblemparade/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:860 +0x5f
    github.com/spf13/cobra.(*Command).ExecuteC(0x1022d20)
    /home/emblemparade/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:974 +0x44
    github.com/spf13/cobra.(*Command).Execute(...)
    /home/emblemparade/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:902
    github.com/tliron/puccini/puccini-tosca/commands.Execute()
    /Depot/Projects/RedHat/puccini/puccini-tosca/commands/root.go:51 +0x4
    main.main()
    /Depot/Projects/RedHat/puccini/puccini-tosca/main.go:11 +0x2
tliron commented 1 year ago

Thanks! This was an error during reporting, where the code was testing for a node template instead of a relationship in this context.