aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiliano Ciavatta2021-07-28 11:33:46 +0000
committerEmiliano Ciavatta2021-07-28 11:33:46 +0000
commite029a04123dc77499d5e953ca81d6b849aa39252 (patch)
treebec72e3b10e6e9a4745ff63fad9166bd4265406a
parent489ae5c7c65e7f60c3a0e5dc86b1e669e7bf67b5 (diff)
Fix error in rule pattern management after hyperscan update
-rw-r--r--rules_manager.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/rules_manager.go b/rules_manager.go
index 5d6cded..736d561 100644
--- a/rules_manager.go
+++ b/rules_manager.go
@@ -21,12 +21,14 @@ import (
"context"
"errors"
"fmt"
- "github.com/flier/gohs/hyperscan"
- "github.com/go-playground/validator/v10"
- log "github.com/sirupsen/logrus"
"sort"
+ "strings"
"sync"
"time"
+
+ "github.com/flier/gohs/hyperscan"
+ "github.com/go-playground/validator/v10"
+ log "github.com/sirupsen/logrus"
)
const DirectionBoth = 0
@@ -336,7 +338,8 @@ func (rm *rulesManagerImpl) validateAndAddRuleLocal(rule *Rule) error {
startID := len(rm.patterns)
for id, pattern := range newPatterns {
rm.patterns = append(rm.patterns, pattern)
- rm.patternsIds[pattern.String()] = uint(startID + id)
+ regex := pattern.String()
+ rm.patternsIds[regex[strings.IndexByte(regex, ':')+1:]] = uint(startID + id)
}
rm.rules[rule.ID] = *rule
@@ -363,7 +366,11 @@ func (rm *rulesManagerImpl) generateDatabase(version RowID) error {
}
func (p *Pattern) BuildPattern() (*hyperscan.Pattern, error) {
- hp, err := hyperscan.ParsePattern(fmt.Sprintf("/%s/", p.Regex))
+ if !strings.HasPrefix(p.Regex, "/") || !strings.HasSuffix(p.Regex, "/") {
+ p.Regex = fmt.Sprintf("/%s/", p.Regex)
+ }
+
+ hp, err := hyperscan.ParsePattern(p.Regex)
if err != nil {
return nil, err
}