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: check mmap result #2003

Merged
merged 3 commits into from
Nov 15, 2023
Merged
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
25 changes: 15 additions & 10 deletions libyara/proc/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,16 @@ YR_API const uint8_t* yr_process_fetch_memory_block_data(YR_MEMORY_BLOCK* block)
fd,
proc_info->map_offset);
close(fd);
if (context->buffer == MAP_FAILED)
{
// Notify the code below that we couldn't read from the file
// fallback to pread() from the process
fd = -1;
}
context->buffer_size = block->size;
}
else

if (fd < 0)
{
context->buffer = mmap(
NULL,
Expand All @@ -228,17 +236,14 @@ YR_API const uint8_t* yr_process_fetch_memory_block_data(YR_MEMORY_BLOCK* block)
MAP_PRIVATE | MAP_ANONYMOUS,
-1,
0);
}

if (context->buffer != NULL)
{
if (context->buffer == MAP_FAILED)
{
context->buffer = NULL;
context->buffer_size = 0;
goto _exit;
}
context->buffer_size = block->size;
}
else
{
context->buffer_size = 0;
goto _exit;
}

// If mapping can't be accessed through the filesystem, read everything from
// target process VM.
Expand Down