From a02116de1290b1f5c7deda43071df762cebc9b84 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Mon, 7 Aug 2023 00:22:12 +0200 Subject: Make the "condition" section mandatory in a rule. --- src/analysis/scan/grammar.y | 3 +-- tests/analysis/scan/fuzzing.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/analysis/scan/grammar.y b/src/analysis/scan/grammar.y index 19a4257..9c3b08b 100644 --- a/src/analysis/scan/grammar.y +++ b/src/analysis/scan/grammar.y @@ -301,8 +301,7 @@ string_decl : IDENTIFIER ASSIGN PLAIN_STRING } ; - condition : /* empty */ - | CONDITION COLON cexpression + condition : CONDITION COLON cexpression { g_scan_rule_set_match_condition(*built_rule, $3); g_object_unref(G_OBJECT($3)); diff --git a/tests/analysis/scan/fuzzing.py b/tests/analysis/scan/fuzzing.py index 64eeb33..0870ed4 100644 --- a/tests/analysis/scan/fuzzing.py +++ b/tests/analysis/scan/fuzzing.py @@ -32,3 +32,17 @@ class TestRostFuzzingFixes(ChrysalideTestCase): 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) -- cgit v0.11.2-87-g4458