@@ -46,12 +46,14 @@ func (p *Parser) FromFile(profilePath string) error {
46
46
if err != nil {
47
47
return fmt .Errorf ("failed to glob: %s" , err .Error ())
48
48
}
49
+
49
50
if len (files ) == 0 {
50
- return fmt . Errorf ("empty glob: %s does not match any file" , profilePath )
51
+ p . options . WAF . Logger . Warn (). Int ( "line" , p . currentLine ). Msg ("empty glob result" )
51
52
}
52
53
} else {
53
54
files = append (files , profilePath )
54
55
}
56
+
55
57
for _ , profilePath := range files {
56
58
profilePath = strings .TrimSpace (profilePath )
57
59
if ! strings .HasPrefix (profilePath , "/" ) {
@@ -157,20 +159,22 @@ func (p *Parser) evaluateLine(l string) error {
157
159
if len (opts ) >= 3 && opts [0 ] == '"' && opts [len (opts )- 1 ] == '"' {
158
160
opts = strings .Trim (opts , `"` )
159
161
}
162
+
160
163
if directive == "include" {
161
164
// this is a special hardcoded case
162
165
// we cannot add it as a directive type because there are recursion issues
163
166
// note a user might still include another file that includes the original file
164
167
// generating a DDOS attack
165
168
if p .includeCount >= maxIncludeRecursion {
166
- return p .log (fmt .Sprintf ("cannot include more than %d files" , maxIncludeRecursion ))
169
+ return p .logAndReturnErr (fmt .Sprintf ("cannot include more than %d files" , maxIncludeRecursion ))
167
170
}
168
171
p .includeCount ++
169
172
return p .FromFile (opts )
170
173
}
174
+
171
175
d , ok := directivesMap [directive ]
172
176
if ! ok || d == nil {
173
- return p .log (fmt .Sprintf ("unknown directive %q" , directive ))
177
+ return p .logAndReturnErr (fmt .Sprintf ("unknown directive %q" , directive ))
174
178
}
175
179
176
180
p .options .Raw = l
@@ -194,7 +198,7 @@ func (p *Parser) evaluateLine(l string) error {
194
198
return nil
195
199
}
196
200
197
- func (p * Parser ) log (msg string ) error {
201
+ func (p * Parser ) logAndReturnErr (msg string ) error {
198
202
p .options .WAF .Logger .Error ().Int ("line" , p .currentLine ).Msg (msg )
199
203
return errors .New (msg )
200
204
}
0 commit comments