Skip to content

Commit

Permalink
Merge pull request #194 from flaviojs/clear-uninitialized-sections-mi…
Browse files Browse the repository at this point in the history
…ps64_load_elf_image

Clear uninitialized sections in mips64_load_elf_image.
  • Loading branch information
grossmj authored Mar 27, 2024
2 parents c2fdb8c + 1ed3370 commit e1dfdd0
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 e1dfdd0

Please sign in to comment.