fix: npe when parse rule

This commit is contained in:
Skyxim
2022-04-16 00:21:08 +08:00
parent 36a719e2f8
commit 45fe6e996b
6 changed files with 86 additions and 42 deletions

View File

@ -19,16 +19,19 @@ func (not *NOT) ShouldFindProcess() bool {
func NewNOT(payload string, adapter string) (*NOT, error) {
not := &NOT{Base: &common.Base{}, payload: payload, adapter: adapter}
rule, err := parseRuleByPayload(payload, false)
rule, err := parseRuleByPayload(payload)
if err != nil {
return nil, err
}
if len(rule) < 1 {
return nil, fmt.Errorf("NOT rule have not a rule")
if len(rule) > 1 {
return nil, fmt.Errorf("not rule can contain at most one rule")
}
if len(rule) > 0 {
not.rule = rule[0]
}
not.rule = rule[0]
return not, nil
}
@ -37,7 +40,7 @@ func (not *NOT) RuleType() C.RuleType {
}
func (not *NOT) Match(metadata *C.Metadata) bool {
return !not.rule.Match(metadata)
return not.rule == nil || !not.rule.Match(metadata)
}
func (not *NOT) Adapter() string {
@ -49,5 +52,5 @@ func (not *NOT) Payload() string {
}
func (not *NOT) ShouldResolveIP() bool {
return not.rule.ShouldResolveIP()
return not.rule != nil && not.rule.ShouldResolveIP()
}