RS used to do a stat, and check that the stat was successful, but it
didn't check that the executable was not actually empty.
This patch adds a check to detect file which are smaller than the minimum
ELF size possible.
Change-Id: I22b004084f17e7d395e2c1377add7bc8b51c3d5e
static int elf_unpack(char *exec_hdr,
int hdr_len, Elf_Ehdr **hdr, Elf_Phdr **phdr)
{
+ assert(hdr_len >= sizeof(Elf_Ehdr));
+
*hdr = (Elf_Ehdr *) exec_hdr;
if(!elf_sane(*hdr)) {
return ENOEXEC;
#include <paths.h>
+#include <sys/exec_elf.h>
+
#include "inc.h"
#include "kernel/proc.h"
if (r != 0)
return -errno;
+ if (sb.st_size < sizeof(Elf_Ehdr))
+ return ENOEXEC;
+
fd= open(e_name, O_RDONLY);
if (fd == -1)
return -errno;