-/* $OpenBSD: exec_elf.c,v 1.143 2018/07/10 04:19:59 guenther Exp $ */
+/* $OpenBSD: exec_elf.c,v 1.144 2018/07/20 21:48:27 kettenis Exp $ */
/*
* Copyright (c) 1996 Per Fogelstrom
for (i = 0; i < eh.e_phnum; i++) {
if (ph[i].p_type == PT_LOAD) {
- if (ph[i].p_filesz > ph[i].p_memsz)
+ if (ph[i].p_filesz > ph[i].p_memsz ||
+ ph[i].p_memsz == 0) {
+ error = EINVAL;
goto bad1;
+ }
loadmap[idx].vaddr = trunc_page(ph[i].p_vaddr);
loadmap[idx].memsz = round_page (ph[i].p_vaddr +
ph[i].p_memsz - loadmap[idx].vaddr);
if (interp[pp->p_filesz - 1] != '\0')
goto bad;
} else if (pp->p_type == PT_LOAD) {
- if (pp->p_filesz > pp->p_memsz) {
+ if (pp->p_filesz > pp->p_memsz ||
+ pp->p_memsz == 0) {
error = EINVAL;
goto bad;
}