Skip to content

Commit

Permalink
If p_memsz is greater than p_filesz, the extra bytes are NOBITS.
Browse files Browse the repository at this point in the history
Fixes #10
  • Loading branch information
Cirromulus committed Feb 25, 2021
1 parent a2e6d78 commit 8c4132e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion vp/src/core/common/elf_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ struct GenericElfLoader {
if ((p->p_filesz == 0) && (p->p_memsz == 0))
continue;

//If p_memsz is greater than p_filesz, the extra bytes are NOBITS.
if (p->p_memsz > p->p_filesz)
continue;

sections.push_back(p);
}

Expand All @@ -51,7 +55,11 @@ struct GenericElfLoader {
if (use_vaddr)
addr = p->p_vaddr;

assert ((addr >= offset) && (addr + p->p_memsz < offset + size));
assert ((addr >= offset) &&
"Offset overlaps into section");

assert ((addr + p->p_memsz < offset + size) &&
"Section does not fit in target memory");

auto idx = addr - offset;
const char *src = elf.data() + p->p_offset;
Expand Down

0 comments on commit 8c4132e

Please sign in to comment.