Skip to content

Commit

Permalink
Merge pull request #692 from ystia/bugfix/GH-691_nil_pointer_in_getAc…
Browse files Browse the repository at this point in the history
…tivityInputParameters

Fix possible nil pointer use when we can't get a workflow definition from store
  • Loading branch information
loicalbertin committed Oct 13, 2020
2 parents 8786efa + f16fbf4 commit 38e70ce
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

### BUG FIXES

* Panic due to nil pointer dereference may happen when retrieving a workflow ([GH-691](https://github.com/ystia/yorc/issues/691))
* Empty directories not removed after ansible executions can lead to inodes exhaustion ([GH-683](https://github.com/ystia/yorc/issues/683))
* Yorc generates forcePurge tasks on list deployments API endpoint ([GH-674](https://github.com/ystia/yorc/issues/674))
* Yorc is getting slow when there is a lot of tasks ([GH-671](https://github.com/ystia/yorc/issues/671))
Expand Down
9 changes: 7 additions & 2 deletions deployments/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ package deployments

import (
"context"
"path"
"strings"

"github.com/ystia/yorc/v4/log"
"github.com/ystia/yorc/v4/storage"
"github.com/ystia/yorc/v4/storage/types"
"path"
"strings"

"github.com/pkg/errors"

Expand Down Expand Up @@ -127,6 +128,10 @@ func ResolveWorkflowOutputs(ctx context.Context, deploymentID, workflowName stri
return nil, err
}

if wf == nil {
return nil, errors.Errorf("Can't resolve outputs of workflow %q in deployment %q, workflow definition not found", workflowName, deploymentID)
}

outputs := make(map[string]*TOSCAValue)
for outputName, outputDef := range wf.Outputs {
dataType := getTypeFromParamDefinition(ctx, &outputDef)
Expand Down
7 changes: 6 additions & 1 deletion rest/dep_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ func (s *Server) newWorkflowHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Panic(err)
}

if wf == nil {
log.Panic(errors.Errorf("Can't check inputs of workflow %q in deployment %q, workflow definition not found", workflowName, deploymentID))
}
for inputName, def := range wf.Inputs {
// A property is considered as required by default, unless def.Required
// is set to false
Expand Down Expand Up @@ -205,5 +207,8 @@ func (s *Server) getWorkflowHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Panic(err)
}
if wf == nil {
log.Panic(errors.Errorf("Can't retrieve workflow %q in deployment %q, workflow definition not found", workflowName, deploymentID))
}
encodeJSONResponse(w, r, Workflow{Name: workflowName, Workflow: *wf})
}
4 changes: 4 additions & 0 deletions tasks/workflow/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func BuildWorkFlow(ctx context.Context, deploymentID, wfName string) (map[string
return nil, err
}

if wf == nil {
return nil, errors.Errorf("Can't build workflow %q in deployment %q, workflow definition not found", wfName, deploymentID)
}

if wf.Steps == nil || len(wf.Steps) == 0 {
return nil, deployments.NewInconsistentDeploymentError(deploymentID)
}
Expand Down
4 changes: 4 additions & 0 deletions tasks/workflow/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ func (s *step) getActivityInputParameters(ctx context.Context, activity builder.
return nil, err
}

if wf == nil {
return nil, errors.Errorf("Can't retrieve inputs for an activity of workflow %q in deployment %q, workflow definition not found", workflowName, deploymentID)
}

for inputName, propDef := range wf.Inputs {

if _, ok := result[inputName]; ok {
Expand Down

0 comments on commit 38e70ce

Please sign in to comment.