Skip to content

Commit

Permalink
fix: handle calloc fail
Browse files Browse the repository at this point in the history
  • Loading branch information
secDre4mer committed Jun 16, 2023
1 parent 12eb727 commit dfa5ae0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libyara/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ int yr_rules_from_arena(YR_ARENA* arena, YR_RULES** rules)
if (new_rules == NULL)
return ERROR_INSUFFICIENT_MEMORY;

new_rules->rule_evaluate_condition_flags = (YR_BITMASK*) yr_calloc(
sizeof(YR_BITMASK), YR_BITMASK_SIZE(new_rules->num_rules));
if (new_rules->rule_evaluate_condition_flags == NULL)
{
yr_free(new_rules);
return ERROR_INSUFFICIENT_MEMORY;
}

// Now YR_RULES relies on this arena, let's increment the arena's
// reference count so that if the original owner of the arena calls
// yr_arena_destroy the arena is not destroyed.
Expand Down Expand Up @@ -367,8 +375,6 @@ int yr_rules_from_arena(YR_ARENA* arena, YR_RULES** rules)
// If a rule has no required_strings, this means that the condition might
// evaluate to true without any matching strings, and we therefore have to
// mark it as "to be evaluated" from the beginning.
new_rules->rule_evaluate_condition_flags = (YR_BITMASK*) yr_calloc(
sizeof(YR_BITMASK), YR_BITMASK_SIZE(new_rules->num_rules));
for (int i = 0; i < new_rules->num_rules; i++)
{
if (new_rules->rules_table[i].required_strings == 0)
Expand Down

0 comments on commit dfa5ae0

Please sign in to comment.