From 9042c0e20de166542b603621fd30dc8be95dfd4d Mon Sep 17 00:00:00 2001 From: ths Date: Sat, 23 Dec 2006 14:18:40 +0000 Subject: Check ELF binaries for machine type and endianness. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2274 c046a42c-6fe2-441c-8c8c-71466251a162 --- elf_ops.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'elf_ops.h') diff --git a/elf_ops.h b/elf_ops.h index 122bf10c1..1cd4f2b3d 100644 --- a/elf_ops.h +++ b/elf_ops.h @@ -153,6 +153,9 @@ int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, glue(bswap_ehdr, SZ)(&ehdr); } + if (ELF_MACHINE != ehdr.e_machine) + goto fail; + if (pentry) *pentry = (uint64_t)ehdr.e_entry; @@ -164,7 +167,7 @@ int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, if (!phdr) goto fail; if (read(fd, phdr, size) != size) - goto fail; + goto fail1; if (must_swab) { for(i = 0; i < ehdr.e_phnum; i++) { ph = &phdr[i]; @@ -181,9 +184,9 @@ int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, data = qemu_mallocz(mem_size); if (ph->p_filesz > 0) { if (lseek(fd, ph->p_offset, SEEK_SET) < 0) - goto fail; + goto fail2; if (read(fd, data, ph->p_filesz) != ph->p_filesz) - goto fail; + goto fail2; } addr = ph->p_vaddr + virt_to_phys_addend; @@ -197,9 +200,11 @@ int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, } qemu_free(phdr); return total_size; - fail: +fail2: qemu_free(data); +fail1: qemu_free(phdr); +fail: return -1; } -- cgit v1.2.3