From 8bbd5527b66e1edd0a4a8a955dba095042b22f59 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Mon, 7 Aug 2023 00:39:02 +0200 Subject: Avoid to count the matches of a non-existing pattern. --- src/analysis/scan/grammar.y | 9 +++++++-- tests/analysis/scan/fuzzing.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/analysis/scan/grammar.y b/src/analysis/scan/grammar.y index 9c3b08b..898b135 100644 --- a/src/analysis/scan/grammar.y +++ b/src/analysis/scan/grammar.y @@ -343,8 +343,13 @@ string_decl : IDENTIFIER ASSIGN PLAIN_STRING { GSearchPattern *__pat; __pat = g_scan_rule_get_local_variable(*built_rule, $1.data); - $$ = g_scan_match_counter_new(__pat); - g_object_unref(G_OBJECT(__pat)); + if (__pat == NULL) + $$ = NULL; + else + { + $$ = g_scan_match_counter_new(__pat); + g_object_unref(G_OBJECT(__pat)); + } } ; diff --git a/tests/analysis/scan/fuzzing.py b/tests/analysis/scan/fuzzing.py index 0870ed4..2140972 100644 --- a/tests/analysis/scan/fuzzing.py +++ b/tests/analysis/scan/fuzzing.py @@ -46,3 +46,20 @@ 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) -- cgit v0.11.2-87-g4458