Commit fd93a79999c728dd1f30bb2e726ce12bdf704e6d
1 parent
bdb11366
Fix elf loader range checking
The ELF loader tracks the range of addresses used by a binary. However this incorrectly assumes zero is not a valid address. Signed-off-by: Paul Brook <paul@codesourcery.com>
Showing
1 changed file
with
3 additions
and
3 deletions
elf_ops.h
... | ... | @@ -185,7 +185,7 @@ static int glue(load_elf, SZ)(int fd, int64_t address_offset, |
185 | 185 | struct elf_phdr *phdr = NULL, *ph; |
186 | 186 | int size, i, total_size; |
187 | 187 | elf_word mem_size; |
188 | - uint64_t addr, low = 0, high = 0; | |
188 | + uint64_t addr, low = (uint64_t)-1, high = 0; | |
189 | 189 | uint8_t *data = NULL; |
190 | 190 | |
191 | 191 | if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr)) |
... | ... | @@ -249,9 +249,9 @@ static int glue(load_elf, SZ)(int fd, int64_t address_offset, |
249 | 249 | cpu_physical_memory_write_rom(addr, data, mem_size); |
250 | 250 | |
251 | 251 | total_size += mem_size; |
252 | - if (!low || addr < low) | |
252 | + if (addr < low) | |
253 | 253 | low = addr; |
254 | - if (!high || (addr + mem_size) > high) | |
254 | + if ((addr + mem_size) > high) | |
255 | 255 | high = addr + mem_size; |
256 | 256 | |
257 | 257 | qemu_free(data); | ... | ... |