PeachOS
PeachOS copied to clipboard
Unhandled possible memory allocation failure in elfloader.c
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;
}
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