aboutsummaryrefslogtreecommitdiff
path: root/elf_ops.h
diff options
context:
space:
mode:
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2006-12-23 14:18:40 +0000
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2006-12-23 14:18:40 +0000
commit9042c0e20de166542b603621fd30dc8be95dfd4d (patch)
tree84ea028032cb2c70fff393af4d94854eea585f3f /elf_ops.h
parent70ead4341212ecb3181d5c780284cef0fc7b51fc (diff)
downloadqemu-9042c0e20de166542b603621fd30dc8be95dfd4d.zip
qemu-9042c0e20de166542b603621fd30dc8be95dfd4d.tar.gz
qemu-9042c0e20de166542b603621fd30dc8be95dfd4d.tar.bz2
Check ELF binaries for machine type and endianness.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2274 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'elf_ops.h')
-rw-r--r--elf_ops.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/elf_ops.h b/elf_ops.h
index 122bf10..1cd4f2b 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;
}