Skip to content

Commit

Permalink
Add a timeout to regexes.
Browse files Browse the repository at this point in the history
This avoids pathologically bad match times. Fixes #378.
  • Loading branch information
alecthomas committed Jul 8, 2020
1 parent 5756434 commit e62d93f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"regexp"
"strings"
"sync"
"time"
"unicode/utf8"

"github.com/dlclark/regexp2"
Expand Down Expand Up @@ -393,6 +394,7 @@ func (r *RegexLexer) maybeCompile() (err error) {
if err != nil {
return fmt.Errorf("failed to compile rule %s.%d: %s", state, i, err)
}
rule.Regexp.MatchTimeout = time.Millisecond * 250
}
}
}
Expand Down

0 comments on commit e62d93f

Please sign in to comment.