@@ -243,12 +243,13 @@ func TestRule(t *testing.T) {
243
243
}
244
244
245
245
type testCallback struct {
246
- t * testing.T
247
- finished bool
248
- modules map [string ]struct {}
249
- matched map [string ]struct {}
250
- notMatched map [string ]struct {}
251
- logged []string
246
+ t * testing.T
247
+ finished bool
248
+ modules map [string ]struct {}
249
+ matched map [string ]struct {}
250
+ notMatched map [string ]struct {}
251
+ logged []string
252
+ tooManyMatches []string
252
253
}
253
254
254
255
func newTestCallback (t * testing.T ) * testCallback {
@@ -258,6 +259,7 @@ func newTestCallback(t *testing.T) *testCallback {
258
259
make (map [string ]struct {}),
259
260
make (map [string ]struct {}),
260
261
nil ,
262
+ nil ,
261
263
}
262
264
}
263
265
@@ -291,6 +293,10 @@ func (c *testCallback) ModuleImported(*ScanContext, *Object) (bool, error) {
291
293
func (c * testCallback ) ConsoleLog (_ * ScanContext , s string ) {
292
294
c .logged = append (c .logged , s )
293
295
}
296
+ func (c * testCallback ) TooManyMatches (_ * ScanContext , r * Rule , s string ) (bool , error ) {
297
+ c .tooManyMatches = append (c .logged , fmt .Sprintf ("%s:%s" , r .Identifier (), s ))
298
+ return false , nil
299
+ }
294
300
295
301
func TestImportDataCallback (t * testing.T ) {
296
302
cb := newTestCallback (t )
@@ -338,3 +344,17 @@ func TestConsoleCallback(t *testing.T) {
338
344
t .Errorf ("console log does not containi expected hello world string: %v" , cb .logged )
339
345
}
340
346
}
347
+
348
+ func TestTooManyMatches (t * testing.T ) {
349
+ cb := newTestCallback (t )
350
+ r := makeRules (t , `
351
+ rule t { strings: $s1 = "\x00" condition: #s1 == 10000000 }
352
+ ` )
353
+
354
+ if err := r .ScanMem (make ([]byte , 10000000 ), 0 , 0 , cb ); err != nil {
355
+ t .Error (err )
356
+ }
357
+ if len (cb .tooManyMatches ) != 1 || cb .tooManyMatches [0 ] != "t:$s1" {
358
+ t .Errorf ("too many matches does not contain regularly matching string: %v" , cb .tooManyMatches )
359
+ }
360
+ }
0 commit comments