elf: Fix potential uninitialised usage of bss_size

This commit is contained in:
mintsuki 2023-07-09 03:09:45 +02:00
parent 9333f1ca8b
commit 17e26c8c95
1 changed files with 4 additions and 4 deletions

View File

@ -534,7 +534,7 @@ again:
} }
} }
uint64_t bss_size; uint64_t bss_size = 0;
for (uint16_t i = 0; i < hdr->ph_num; i++) { for (uint16_t i = 0; i < hdr->ph_num; i++) {
struct elf64_phdr *phdr = (void *)elf + (hdr->phoff + i * hdr->phdr_size); struct elf64_phdr *phdr = (void *)elf + (hdr->phoff + i * hdr->phdr_size);
@ -566,9 +566,7 @@ again:
memcpy((void *)(uintptr_t)load_addr, elf + (phdr->p_offset), phdr->p_filesz); memcpy((void *)(uintptr_t)load_addr, elf + (phdr->p_offset), phdr->p_filesz);
if (i == hdr->ph_num - 1) { bss_size = phdr->p_memsz - phdr->p_filesz;
bss_size = phdr->p_memsz - phdr->p_filesz;
}
if (!elf64_apply_relocations(elf, hdr, (void *)(uintptr_t)load_addr, phdr->p_vaddr, phdr->p_memsz, slide)) { if (!elf64_apply_relocations(elf, hdr, (void *)(uintptr_t)load_addr, phdr->p_vaddr, phdr->p_memsz, slide)) {
panic(true, "elf: Failed to apply relocations"); panic(true, "elf: Failed to apply relocations");
@ -580,6 +578,8 @@ again:
#endif #endif
} }
bss_size = 0;
if (_image_size_before_bss != NULL) { if (_image_size_before_bss != NULL) {
*_image_size_before_bss = image_size - bss_size; *_image_size_before_bss = image_size - bss_size;
} }