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

Fix null derefrences while loading compiled rules #1727

Merged
merged 3 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libyara/arena.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,8 @@ int yr_arena_load_stream(YR_STREAM* stream, YR_ARENA** arena)
YR_ARENA_BUFFER* b = &new_arena->buffers[reloc_ref.buffer_id];

if (reloc_ref.buffer_id >= new_arena->num_buffers ||
reloc_ref.offset > b->used - sizeof(void*))
reloc_ref.offset > b->used - sizeof(void*) ||
b->data == NULL)
{
yr_arena_release(new_arena);
return ERROR_CORRUPT_FILE;
Expand Down
1 change: 1 addition & 0 deletions libyara/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ int yr_object_create(
size_t object_size = 0;

assert(parent != NULL || object != NULL);
assert(identifier != NULL);

switch (type)
{
Expand Down
3 changes: 3 additions & 0 deletions libyara/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ int yr_rules_from_arena(YR_ARENA* arena, YR_RULES** rules)
YR_SUMMARY* summary = (YR_SUMMARY*) yr_arena_get_ptr(
arena, YR_SUMMARY_SECTION, 0);

if (summary == NULL)
return ERROR_CORRUPT_FILE;

// 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