From dbe05c349a0892306d7317d3c26a56e9b19eca92 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sun, 6 Aug 2023 23:40:42 +0200 Subject: Prevent the ACISM backend from crashing when a scan is performed with no pattern. --- src/analysis/scan/patterns/backends/acism.c | 3 +++ tests/analysis/scan/fuzzing.py | 34 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/analysis/scan/fuzzing.py diff --git a/src/analysis/scan/patterns/backends/acism.c b/src/analysis/scan/patterns/backends/acism.c index eef681a..97f8561 100644 --- a/src/analysis/scan/patterns/backends/acism.c +++ b/src/analysis/scan/patterns/backends/acism.c @@ -1165,6 +1165,7 @@ static void g_acism_backend_run_scan(const GAcismBackend *backend, GScanContext #endif root = backend->states; + if (root == NULL) goto done; state = root; @@ -1240,6 +1241,8 @@ static void g_acism_backend_run_scan(const GAcismBackend *backend, GScanContext } + done: + g_object_unref(G_OBJECT(content)); } diff --git a/tests/analysis/scan/fuzzing.py b/tests/analysis/scan/fuzzing.py new file mode 100644 index 0000000..64eeb33 --- /dev/null +++ b/tests/analysis/scan/fuzzing.py @@ -0,0 +1,34 @@ + +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) -- cgit v0.11.2-87-g4458