Skip to content

Commit a1b4885

Browse files
fixed crash compiling unknown rules operator
If a rule contained an unknown rule type or unknown operand, the daemon crashed. Issue: #1295
1 parent bcfae74 commit a1b4885

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

daemon/rule/loader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ func (l *Loader) loadRule(fileName string) error {
189189
}
190190
} else {
191191
if err := r.Operator.Compile(); err != nil {
192-
log.Warning("Operator.Compile() error: %s: %s", err, r.Operator.Data)
192+
log.Warning("Operator.Compile() error: %s: %s (%s)", err, r.Operator.Data, r.Name)
193193
return fmt.Errorf("(1) Error compiling rule: %s", err)
194194
}
195195
if r.Operator.Type == List {
196196
for i := 0; i < len(r.Operator.List); i++ {
197197
if err := r.Operator.List[i].Compile(); err != nil {
198-
log.Warning("Operator.Compile() error: %s: ", err)
198+
log.Warning("Operator.Compile() error: %s (%s)", err, r.Name)
199199
return fmt.Errorf("(1) Error compiling list rule: %s", err)
200200
}
201201
}

daemon/rule/operator.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,30 +111,6 @@ func (o *Operator) Compile() error {
111111
return err
112112
}
113113
o.re = re
114-
} else if o.Operand == OpDomainsLists {
115-
if o.Data == "" {
116-
return fmt.Errorf("Operand lists is empty, nothing to load: %s", o)
117-
}
118-
o.loadLists()
119-
o.cb = o.domainsListCmp
120-
} else if o.Operand == OpDomainsRegexpLists {
121-
if o.Data == "" {
122-
return fmt.Errorf("Operand regexp lists is empty, nothing to load: %s", o)
123-
}
124-
o.loadLists()
125-
o.cb = o.reListCmp
126-
} else if o.Operand == OpIPLists {
127-
if o.Data == "" {
128-
return fmt.Errorf("Operand ip lists is empty, nothing to load: %s", o)
129-
}
130-
o.loadLists()
131-
o.cb = o.ipListCmp
132-
} else if o.Operand == OpNetLists {
133-
if o.Data == "" {
134-
return fmt.Errorf("Operand net lists is empty, nothing to load: %s", o)
135-
}
136-
o.loadLists()
137-
o.cb = o.ipNetCmp
138114
} else if o.Type == List {
139115
o.Operand = OpList
140116
} else if o.Type == Network {
@@ -144,7 +120,31 @@ func (o *Operator) Compile() error {
144120
return err
145121
}
146122
o.cb = o.cmpNetwork
123+
} else if o.Type == Lists {
124+
if o.Data == "" {
125+
return fmt.Errorf("Operand lists is empty, nothing to load: %s", o)
126+
}
127+
128+
if o.Operand == OpDomainsLists {
129+
o.loadLists()
130+
o.cb = o.domainsListCmp
131+
} else if o.Operand == OpDomainsRegexpLists {
132+
o.loadLists()
133+
o.cb = o.reListCmp
134+
} else if o.Operand == OpIPLists {
135+
o.loadLists()
136+
o.cb = o.ipListCmp
137+
} else if o.Operand == OpNetLists {
138+
o.loadLists()
139+
o.cb = o.ipNetCmp
140+
} else {
141+
return fmt.Errorf("Unknown Lists operand: %s", o.Operand)
142+
}
143+
144+
} else {
145+
return fmt.Errorf("Unknown type: %s", o.Type)
147146
}
147+
148148
log.Debug("Operator compiled: %s", o)
149149
o.isCompiled = true
150150

0 commit comments

Comments
 (0)