aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki@daynix.com>2024-03-07 19:20:55 +0900
committerPeter Maydell <peter.maydell@linaro.org>2024-03-11 17:06:06 +0000
commit667909478b09f9f16b03b7e7b11f3c42e7bdcdf3 (patch)
tree0b46d12693b10f3f085f42bf2992a037db99a44d /contrib
parent2aa205f7c6339cb46d26473a0434a292fc3d32cf (diff)
downloadqemu-667909478b09f9f16b03b7e7b11f3c42e7bdcdf3.zip
qemu-667909478b09f9f16b03b7e7b11f3c42e7bdcdf3.tar.gz
qemu-667909478b09f9f16b03b7e7b11f3c42e7bdcdf3.tar.bz2
contrib/elf2dmp: Ensure segment fits in file
This makes elf2dmp more robust against corrupted inputs. Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Tested-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu> Message-id: 20240307-elf2dmp-v4-12-4f324ad4d99d@daynix.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'contrib')
-rw-r--r--contrib/elf2dmp/addrspace.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c
index e01860d..81295a1 100644
--- a/contrib/elf2dmp/addrspace.c
+++ b/contrib/elf2dmp/addrspace.c
@@ -88,11 +88,12 @@ void pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf)
ps->block = g_new(struct pa_block, ps->block_nr);
for (i = 0; i < phdr_nr; i++) {
- if (phdr[i].p_type == PT_LOAD) {
+ if (phdr[i].p_type == PT_LOAD && phdr[i].p_offset < qemu_elf->size) {
ps->block[block_i] = (struct pa_block) {
.addr = (uint8_t *)qemu_elf->map + phdr[i].p_offset,
.paddr = phdr[i].p_paddr,
- .size = phdr[i].p_filesz,
+ .size = MIN(phdr[i].p_filesz,
+ qemu_elf->size - phdr[i].p_offset),
};
pa_block_align(&ps->block[block_i]);
block_i = ps->block[block_i].size ? (block_i + 1) : block_i;