Skip to content

Commit f7b483a

Browse files
committed
fix: explicitly cancel context on early return in beginScan (gosec G118)
Made-with: Cursor
1 parent c7ac906 commit f7b483a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

internal/tui/model.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,19 @@ func (m Model) updateForm(msg tea.Msg) (tea.Model, tea.Cmd) {
9696
}
9797

9898
func (m Model) beginScan(vals formValues) (tea.Model, tea.Cmd) {
99+
// Create the context up front so cancel is always assigned to the model
100+
// before any early return. This satisfies static analysis tools that
101+
// require the cancellation function to be demonstrably reachable.
102+
ctx, cancel := context.WithCancel(context.Background())
103+
m.cancel = cancel
104+
99105
entries, _, err := wordlist.LoadWordlist(vals.wordlist)
100106
if err != nil {
107+
cancel() // explicitly cancel before returning on error
101108
m.form.err = "cannot read wordlist: " + err.Error()
102109
return m, nil
103110
}
104111

105-
ctx, cancel := context.WithCancel(context.Background())
106-
m.cancel = cancel
107112
m.state = stateScan
108113
m.scanView = newScanViewModel(m.width, m.height, vals.simulate)
109114

0 commit comments

Comments
 (0)