Skip to content

Unhandled possible memory allocation failure in elfloader.c #36

@jdunlap

Description

@jdunlap

In elfloader.c, starting on line 209 in elf_load, we have the following code:

elf_file->elf_memory = kzalloc(stat.filesize);
    res = fread(elf_file->elf_memory, stat.filesize, 1, fd);
    if (res < 0)
    {
        goto out;
    }

It is possible that the kzalloc on line 209 could fail, but that is not checked which could result in an issue. It should be changed to:

elf_file->elf_memory = kzalloc(stat.filesize);
if (!elf_file->elf_memory)
{
    res = -ENOMEM;
    goto out;
}
res = fread(elf_file->elf_memory, stat.filesize, 1, fd);
if (res < 0)
{
    goto out;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions