Fixed a crash in workflow loader

dev
Ice3man543 2021-08-30 16:58:11 +05:30
parent 482fea58a8
commit 1946d2ec52
2 changed files with 7 additions and 3 deletions

View File

@ -85,7 +85,7 @@ func Parse(filePath string, preprocessor Preprocessor, options protocols.Execute
if len(template.Workflows) > 0 { if len(template.Workflows) > 0 {
compiled := &template.Workflow compiled := &template.Workflow
compileWorkflow(preprocessor, &options, compiled, options.WorkflowLoader) compileWorkflow(filePath, preprocessor, &options, compiled, options.WorkflowLoader)
template.CompiledWorkflow = compiled template.CompiledWorkflow = compiled
template.CompiledWorkflow.Options = &options template.CompiledWorkflow.Options = &options
} }

View File

@ -1,6 +1,7 @@
package templates package templates
import ( import (
"github.com/pkg/errors"
"github.com/projectdiscovery/gologger" "github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v2/pkg/model" "github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols" "github.com/projectdiscovery/nuclei/v2/pkg/protocols"
@ -8,10 +9,10 @@ import (
) )
// compileWorkflow compiles the workflow for execution // compileWorkflow compiles the workflow for execution
func compileWorkflow(preprocessor Preprocessor, options *protocols.ExecuterOptions, workflow *workflows.Workflow, loader model.WorkflowLoader) { func compileWorkflow(path string, preprocessor Preprocessor, options *protocols.ExecuterOptions, workflow *workflows.Workflow, loader model.WorkflowLoader) {
for _, workflow := range workflow.Workflows { for _, workflow := range workflow.Workflows {
if err := parseWorkflow(preprocessor, workflow, options, loader); err != nil { if err := parseWorkflow(preprocessor, workflow, options, loader); err != nil {
gologger.Warning().Msgf("Could not parse workflow: %v\n", err) gologger.Warning().Msgf("Could not parse workflow %s: %v\n", path, err)
continue continue
} }
} }
@ -21,6 +22,9 @@ func compileWorkflow(preprocessor Preprocessor, options *protocols.ExecuterOptio
func parseWorkflow(preprocessor Preprocessor, workflow *workflows.WorkflowTemplate, options *protocols.ExecuterOptions, loader model.WorkflowLoader) error { func parseWorkflow(preprocessor Preprocessor, workflow *workflows.WorkflowTemplate, options *protocols.ExecuterOptions, loader model.WorkflowLoader) error {
shouldNotValidate := false shouldNotValidate := false
if len(workflow.Template) == 0 && workflow.Tags.IsEmpty() {
return errors.New("invalid workflow with no templates or tags")
}
if len(workflow.Subtemplates) > 0 || len(workflow.Matchers) > 0 { if len(workflow.Subtemplates) > 0 || len(workflow.Matchers) > 0 {
shouldNotValidate = true shouldNotValidate = true
} }