Skip to content

Commit 1874d5b

Browse files
authored
fix: prevent nil pointer dereference on context cancellation (#6085)
1 parent 357fe9e commit 1874d5b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pkg/core/execute_options.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func (e *Engine) executeTemplateSpray(ctx context.Context, templatesList []*temp
107107
// wp is workpool that contains different waitgroups for
108108
// headless and non-headless templates
109109
wp := e.GetWorkPool()
110+
defer wp.Wait()
110111

111112
for _, template := range templatesList {
112113
select {
@@ -135,14 +136,14 @@ func (e *Engine) executeTemplateSpray(ctx context.Context, templatesList []*temp
135136
e.executeTemplateWithTargets(ctx, tpl, target, results)
136137
}(template)
137138
}
138-
wp.Wait()
139139
return results
140140
}
141141

142142
// executeHostSpray executes scan using host spray strategy where templates are iterated over each target
143143
func (e *Engine) executeHostSpray(ctx context.Context, templatesList []*templates.Template, target provider.InputProvider) *atomic.Bool {
144144
results := &atomic.Bool{}
145145
wp, _ := syncutil.New(syncutil.WithSize(e.options.BulkSize + e.options.HeadlessBulkSize))
146+
defer wp.Wait()
146147

147148
target.Iterate(func(value *contextargs.MetaInput) bool {
148149
select {
@@ -158,7 +159,6 @@ func (e *Engine) executeHostSpray(ctx context.Context, templatesList []*template
158159
}(value)
159160
return true
160161
})
161-
wp.Wait()
162162
return results
163163
}
164164

pkg/core/executors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func (e *Engine) executeTemplatesOnTarget(ctx context.Context, alltemplates []*t
163163
// headless and non-headless templates
164164
// global waitgroup should not be used here
165165
wp := e.GetWorkPool()
166+
defer wp.Wait()
166167

167168
for _, tpl := range alltemplates {
168169
select {
@@ -210,5 +211,4 @@ func (e *Engine) executeTemplatesOnTarget(ctx context.Context, alltemplates []*t
210211
results.CompareAndSwap(false, match)
211212
}(tpl, target, sg)
212213
}
213-
wp.Wait()
214214
}

0 commit comments

Comments
 (0)