Skip to content

Commit

Permalink
fix: check first block in magic module
Browse files Browse the repository at this point in the history
For the magic module, this bug (see previous commit) is less reachable,
since if the SCAN_FLAGS_PROCESS_MEMORY is set, we do not reach this
code. However, with a custom block iterator and without this flag, the
block value could be NULL.
  • Loading branch information
vthib committed Nov 29, 2023
1 parent aeed773 commit ce07237
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libyara/modules/magic/magic.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ define_function(magic_mime_type)
if (cache->cached_mime_type == NULL)
{
block = first_memory_block(context);

if (block == NULL)
return_string(YR_UNDEFINED);

block_data = block->fetch_data(block);

if (block_data != NULL)
Expand Down Expand Up @@ -134,6 +138,10 @@ define_function(magic_type)
if (cache->cached_type == NULL)
{
block = first_memory_block(context);

if (block == NULL)
return_string(YR_UNDEFINED);

block_data = block->fetch_data(block);

if (block_data != NULL)
Expand Down

0 comments on commit ce07237

Please sign in to comment.