PeachOS icon indicating copy to clipboard operation
PeachOS copied to clipboard

Unhandled possible memory allocation failure in elfloader.c

Open jdunlap opened this issue 3 months ago • 1 comments

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;
}

jdunlap avatar Oct 30 '25 02:10 jdunlap

Yes you are correct, you will see lots of little things like this in the kernel because we focus more on teaching kernel development, so small issues like that while serious in a production project sometimes can go overlooked as the focus of this course is to teach kernel development.

This repository will not be updated further because we have a part two video course but i will keep your issue report for anyone who is interested

nibblebits avatar Oct 30 '25 13:10 nibblebits