Repository: avast/yaramod (language: python)

Issue:
Empty `strings` part of the rule is parsed without error
When strings keyword is present in the rule, but there are no strings, YARA fails with error. However, yaramod parses it without error.
Example:
```
rule a {
    strings:
    condition:
        true
}
```


Discussion / hints:

Fix patch:
diff --git a/src/parser/parser_driver.cpp b/src/parser/parser_driver.cpp
index 47d46d72..65717fac 100644
--- a/src/parser/parser_driver.cpp
+++ b/src/parser/parser_driver.cpp
@@ -652,13 +652,13 @@ void ParserDriver::defineGrammar()
 	}
 
 	_parser.rule("strings") // shared_ptr<StringsTrie>
-		.production("STRINGS", "COLON", "strings_body", [](auto&& args) -> Value {
+		.production("STRINGS", "COLON", "strings_body_nonempty", [](auto&& args) -> Value {
 			args[1].getTokenIt()->setType(TokenType::COLON_BEFORE_NEWLINE);
 			return std::move(args[2]);
 		})
 		;
 
-	_parser.rule("strings_body") // shared_ptr<StringsTrie>
+	_parser.rule("strings_body_nonempty") // shared_ptr<StringsTrie>
 		.production(
 			"strings_body", "STRING_ID", "ASSIGN", [](auto&& args) -> Value {
 				args[1].getTokenIt()->setType(TokenType::STRING_ID_AFTER_NEWLINE);
@@ -676,13 +676,17 @@ void ParserDriver::defineGrammar()
 				}
 				return strings;
 			}
-		)
+		);
+
+	_parser.rule("strings_body") // shared_ptr<StringsTrie>
+		.production("strings_body_nonempty", [&](auto&& args) -> Value {
+			return std::move(args[0].getStringsTrie());
+		})
 		.production([&](auto&&) -> Value {
 			auto strings = std::make_shared<Rule::StringsTrie>();
 			setCurrentStrings(strings);
 			return strings;
-		})
-		;
+		});
 
 	_parser.rule("string")
 		.production("STRING_LITERAL", "plain_string_mods", [&](auto&& args) -> Value {


Test patch:
diff --git a/tests/cpp/parser_tests.cpp b/tests/cpp/parser_tests.cpp
index 77134c7e..5310124d 100644
--- a/tests/cpp/parser_tests.cpp
+++ b/tests/cpp/parser_tests.cpp
@@ -327,6 +327,29 @@ rule variable_in_condition
 	EXPECT_EQ(input_text, driver.getParsedFile().getTextFormatted());
 }
 
+TEST_F(ParserTests,
+RuleWithNoStringsDoesntWork) {
+	prepareInput(
+R"(
+rule rule_with_no_strings
+{
+	strings:
+	condition:
+		true
+}
+)");
+	try
+	{
+		driver.parse(input);
+		FAIL() << "Parser did not throw an exception.";
+	}
+	catch (const ParserError& err)
+	{
+		EXPECT_EQ(0u, driver.getParsedFile().getRules().size());
+		EXPECT_EQ("Error at 5.2-10: Syntax error: Unexpected condition, expected one of string identifier", err.getErrorMessage());
+	}
+}
+
 TEST_F(ParserTests,
 RuleWithPlainTextStringsWorks) {
 	prepareInput(