fixed regexp rules exceptions

- ui, ruleseditor: added missing operator when using a regular
  expression on the DstIP/Net field.
- daemon, rules: ensure that regular expressions are of type string
  before evaluating them.

reported here: #333
This commit is contained in:
Gustavo Iñiguez Goia 2021-01-17 16:31:13 +01:00
parent b1dd51be7a
commit b4672830cd
2 changed files with 6 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package rule
import (
"fmt"
"net"
"reflect"
"regexp"
"strings"
@ -122,6 +123,10 @@ func (o *Operator) simpleCmp(v interface{}) bool {
}
func (o *Operator) reCmp(v interface{}) bool {
if vt := reflect.ValueOf(v).Kind(); vt != reflect.String {
log.Warning("Operator.reCmp() bad interface type: %T", v)
return false
}
if o.Sensitive == false {
v = strings.ToLower(v.(string))
}

View file

@ -450,6 +450,7 @@ class RulesEditorDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
self.rule.operator.type = "network"
if self._is_regex(dstIPtext):
self.rule.operator.operand = "dest.ip"
self.rule.operator.type = "regexp"
if self._is_valid_regex(self.dstIPCombo.currentText()) == False:
return False, QtCore.QCoreApplication.translate("rules", "Dst IP regexp error")