fix: prevent nil pointer dereference on context cancellation (#6085)

This commit is contained in:
Nakul Bharti 2025-03-07 20:34:27 +05:30 committed by GitHub
parent 357fe9efa7
commit 1874d5b900
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -107,6 +107,7 @@ func (e *Engine) executeTemplateSpray(ctx context.Context, templatesList []*temp
// wp is workpool that contains different waitgroups for
// headless and non-headless templates
wp := e.GetWorkPool()
defer wp.Wait()
for _, template := range templatesList {
select {
@ -135,7 +136,6 @@ func (e *Engine) executeTemplateSpray(ctx context.Context, templatesList []*temp
e.executeTemplateWithTargets(ctx, tpl, target, results)
}(template)
}
wp.Wait()
return results
}
@ -143,6 +143,7 @@ func (e *Engine) executeTemplateSpray(ctx context.Context, templatesList []*temp
func (e *Engine) executeHostSpray(ctx context.Context, templatesList []*templates.Template, target provider.InputProvider) *atomic.Bool {
results := &atomic.Bool{}
wp, _ := syncutil.New(syncutil.WithSize(e.options.BulkSize + e.options.HeadlessBulkSize))
defer wp.Wait()
target.Iterate(func(value *contextargs.MetaInput) bool {
select {
@ -158,7 +159,6 @@ func (e *Engine) executeHostSpray(ctx context.Context, templatesList []*template
}(value)
return true
})
wp.Wait()
return results
}

View File

@ -163,6 +163,7 @@ func (e *Engine) executeTemplatesOnTarget(ctx context.Context, alltemplates []*t
// headless and non-headless templates
// global waitgroup should not be used here
wp := e.GetWorkPool()
defer wp.Wait()
for _, tpl := range alltemplates {
select {
@ -210,5 +211,4 @@ func (e *Engine) executeTemplatesOnTarget(ctx context.Context, alltemplates []*t
results.CompareAndSwap(false, match)
}(tpl, target, sg)
}
wp.Wait()
}