Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YaraRuleBuilder allows empty string meta values (issue #58) #59

Merged
merged 2 commits into from
Jan 29, 2020

Conversation

TadeasKucera
Copy link
Contributor

YaraRuleBuilder allows now to create string meta with empty string as value.

Copy link
Member

@s3rvac s3rvac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix of #58 👍 The fix is correct from my point of view. I have included two remarks for consideration.

@@ -176,8 +176,8 @@ YaraRuleBuilder& YaraRuleBuilder::withComment(const std::string& comment, bool m
*/
YaraRuleBuilder& YaraRuleBuilder::withStringMeta(const std::string& key, const std::string& value)
{
if (key == std::string{} || value == std::string{})
throw RuleBuilderError("Error: String-Meta key and value must be non-empty.");
if (key == std::string{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: Here, we basically ask if key is empty. The more straightforward way would be to use if (key.empty()), which does exactly what we need and sounds better when read in English ("if key is empty"). Also, we will no longer need to create an empty string just to use it for comparison and then destroy it.

If you like the tip, feel free to commit it separately as it is not related to the present PR. I just wanted to point that out.

Copy link
Contributor Author

@TadeasKucera TadeasKucera Jan 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the tip, I totally agree. I will commit it in separate PR.

@@ -141,6 +141,37 @@ RuleWithMetasWorks) {
)", yaraFile->getTextFormatted());
}

TEST_F(BuilderTests,
RuleWithEmptyStringMetasWorks) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider naming the test RuleWithEmptyStringMetaValueWorks as we actually check that an empty value is permitted (an empty key is still forbidden).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review, I have fixed the code as you suggested. The first of your tips will come as a separate PR.

@metthal metthal merged commit 741816a into master Jan 29, 2020
@metthal metthal deleted the build_empty_meta branch January 29, 2020 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants