[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2] load_elf: fix iterators' types for elf file processing
From: |
Anastasia Belova |
Subject: |
[PATCH v2] load_elf: fix iterators' types for elf file processing |
Date: |
Fri, 12 Jan 2024 14:45:27 +0300 |
i and size should be the same type as ehdr.e_phnum (Elf32_Half or
Elf64_Half) to avoid overflows. So the bigger one is chosen.
j should be the same type as file_size for the same reasons.
This commit fixes a minor bug, maybe even a typo.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: 7ef295ea5b ("loader: Add data swap option to load-elf")
Signed-off-by: Anastasia Belova <abelova@astralinux.ru>
---
include/hw/elf_ops.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index 0a5c258fe6..6e807708f3 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -325,7 +325,7 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
{
struct elfhdr ehdr;
struct elf_phdr *phdr = NULL, *ph;
- int size, i;
+ Elf64_Half size, i;
ssize_t total_size;
elf_word mem_size, file_size, data_offset;
uint64_t addr, low = (uint64_t)-1, high = 0;
@@ -464,7 +464,7 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
* the ROM overlap check in loader.c, so we don't try to
* explicitly detect those here.
*/
- int j;
+ Elf64_Half j;
elf_word zero_start = ph->p_paddr + file_size;
elf_word zero_end = ph->p_paddr + mem_size;
@@ -500,7 +500,7 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
}
if (data_swab) {
- int j;
+ elf_word j;
for (j = 0; j < file_size; j += (1 << data_swab)) {
uint8_t *dp = data + j;
switch (data_swab) {
--
2.30.2