summaryrefslogtreecommitdiff
path: root/tests/analysis/scan/fuzzing.py
blob: 214097244e381fe4210e0f0c21a55e22f22f1b3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

from chrysacase import ChrysalideTestCase
from pychrysalide.analysis.contents import MemoryContent
from pychrysalide.analysis.scan import ContentScanner
from pychrysalide.analysis.scan import ScanOptions
from pychrysalide.analysis.scan.patterns.backends import AcismBackend
from pychrysalide.analysis.scan.patterns.backends import BitapBackend


class TestRostFuzzingFixes(ChrysalideTestCase):
    """TestCases to remember all the fixes for crashes identified by fuzzing."""

    def testEmptyPatternListWithContent(self):
        """Check no backend is run if there is no pattern to look for."""

        content = MemoryContent(b'\n')

        rule = '''
'''

        backends = [
            AcismBackend, # This one was segfaulting
            BitapBackend,
        ]

        for b in backends:

            options = ScanOptions()
            options.backend_for_data = b

            scanner = ContentScanner(rule)
            ctx = scanner.analyze(options, content)

            self.assertIsNotNone(ctx)


    def testMandatoryCondition(self):
        """Ensure a condition section exists in a rule."""

        rule = '''
rule test {

}
'''

        with self.assertRaisesRegex(ValueError, 'Unable to create content scanner'):

            scanner = ContentScanner(rule)


    def testNonExistingPattern(self):
        """Avoid to count the matches of a non-existing pattern."""

        rule = '''
rule test {

   condition:
      #badid

}
'''

        with self.assertRaisesRegex(ValueError, 'Unable to create content scanner'):

            scanner = ContentScanner(rule)