Skip to content

Commit

Permalink
fixed race condition in RunCmdWithOutputParser
Browse files Browse the repository at this point in the history
  • Loading branch information
eranturgeman committed Nov 28, 2023
1 parent 30d7647 commit ef079aa
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions io/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ func RunCmdWithOutputParser(config CmdConfig, prompt bool, regExpStruct ...*CmdO
for _, regExp := range regExpStruct {
matched := regExp.RegExp.Match([]byte(line))
if matched {
regExp.MatchedResults = regExp.RegExp.FindStringSubmatch(line)
regExp.Line = line
line, err = regExp.ExecFunc(regExp)
results := CmdOutputPattern{
MatchedResults: regExp.RegExp.FindStringSubmatch(line),
Line: line,
}
line, err = regExp.ExecFunc(&results)
if err != nil {
errChan <- err
}
Expand All @@ -117,8 +119,11 @@ func RunCmdWithOutputParser(config CmdConfig, prompt bool, regExpStruct ...*CmdO
for _, regExp := range regExpStruct {
matched := regExp.RegExp.Match([]byte(line))
if matched {
regExp.MatchedResults = regExp.RegExp.FindStringSubmatch(line)
regExp.Line = line
results := CmdOutputPattern{
MatchedResults: regExp.RegExp.FindStringSubmatch(line),
Line: line,
}
line, err = regExp.ExecFunc(&results)

Check failure on line 126 in io/cmd.go

View workflow job for this annotation

GitHub Actions / Static-Check

this value of line is never used (SA4006)
line, scannerError = regExp.ExecFunc(regExp)
if scannerError != nil {
errChan <- scannerError
Expand Down

0 comments on commit ef079aa

Please sign in to comment.