Skip to content

Commit

Permalink
Clear uninitialized sections in mips64_load_elf_image.
Browse files Browse the repository at this point in the history
Elf sections of type SHT_NOBITS do not contain data in the file.
It was either reading junk data or failing to read.
  • Loading branch information
flaviojs committed Mar 27, 2024
1 parent c2fdb8c commit 1ed3370
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 10 additions & 5 deletions stable/mips64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,11 +1013,16 @@ int mips64_load_elf_image(cpu_mips_t *cpu,char *filename,int skip_load,

clen = m_min(clen,remain);

if (fread((u_char *)haddr,clen,1,bfd) != 1) {
perror("load_elf_image: fread");
elf_end(img_elf);
fclose(bfd);
return(-1);
if (shdr->sh_type == SHT_NOBITS) {
// section with uninitialized data, zero it
memset((u_char *)haddr, 0, clen);
} else {
if (fread((u_char *)haddr,clen,1,bfd) != 1) {
perror("load_elf_image: fread");
elf_end(img_elf);
fclose(bfd);
return(-1);
}
}

vaddr += clen;
Expand Down
15 changes: 10 additions & 5 deletions unstable/mips64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1096,11 +1096,16 @@ int mips64_load_elf_image(cpu_mips_t *cpu,char *filename,int skip_load,

clen = m_min(clen,remain);

if (fread((u_char *)haddr,clen,1,bfd) != 1) {
perror("load_elf_image: fread");
elf_end(img_elf);
fclose(bfd);
return(-1);
if (shdr->sh_type == SHT_NOBITS) {
// section with uninitialized data, zero it
memset((u_char *)haddr, 0, clen);
} else {
if (fread((u_char *)haddr,clen,1,bfd) != 1) {
perror("load_elf_image: fread");
elf_end(img_elf);
fclose(bfd);
return(-1);
}
}

vaddr += clen;
Expand Down

0 comments on commit 1ed3370

Please sign in to comment.