Skip to content

Commit

Permalink
Merge pull request #178 from flaviojs/ensure-mips64_load_elf_image-re…
Browse files Browse the repository at this point in the history
…ads-everything

Ensure mips64_load_elf_image reads everything.
  • Loading branch information
grossmj authored Mar 15, 2024
2 parents f1bd8b4 + 81ac92c commit 7fcdd10
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
17 changes: 14 additions & 3 deletions stable/mips64.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,12 @@ int mips64_load_elf_image(cpu_mips_t *cpu,char *filename,int skip_load,
if (!(shdr->sh_flags & SHF_ALLOC) || !len)
continue;

fseek(bfd,shdr->sh_offset,SEEK_SET);
if (fseek(bfd,shdr->sh_offset,SEEK_SET) != 0) {
perror("load_elf_image: fseek");
elf_end(img_elf);
fclose(bfd);
return(-1);
}
vaddr = sign_extend(shdr->sh_addr,32);

if (cpu->vm->debug_level > 0) {
Expand All @@ -993,6 +998,8 @@ int mips64_load_elf_image(cpu_mips_t *cpu,char *filename,int skip_load,
if (!haddr) {
fprintf(stderr,"load_elf_image: invalid load address 0x%llx\n",
vaddr);
elf_end(img_elf);
fclose(bfd);
return(-1);
}

Expand All @@ -1006,8 +1013,12 @@ 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)
break;
if (fread((u_char *)haddr,clen,1,bfd) != 1) {
perror("load_elf_image: fread");
elf_end(img_elf);
fclose(bfd);
return(-1);
}

vaddr += clen;
len -= clen;
Expand Down
17 changes: 14 additions & 3 deletions unstable/mips64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,12 @@ int mips64_load_elf_image(cpu_mips_t *cpu,char *filename,int skip_load,
if (!(shdr->sh_flags & SHF_ALLOC) || !len)
continue;

fseek(bfd,shdr->sh_offset,SEEK_SET);
if (fseek(bfd,shdr->sh_offset,SEEK_SET) != 0) {
perror("load_elf_image: fseek");
elf_end(img_elf);
fclose(bfd);
return(-1);
}
vaddr = sign_extend(shdr->sh_addr,32);

if (cpu->vm->debug_level > 0) {
Expand All @@ -1076,6 +1081,8 @@ int mips64_load_elf_image(cpu_mips_t *cpu,char *filename,int skip_load,
if (!haddr) {
fprintf(stderr,"load_elf_image: invalid load address 0x%llx\n",
vaddr);
elf_end(img_elf);
fclose(bfd);
return(-1);
}

Expand All @@ -1089,8 +1096,12 @@ 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)
break;
if (fread((u_char *)haddr,clen,1,bfd) != 1) {
perror("load_elf_image: fread");
elf_end(img_elf);
fclose(bfd);
return(-1);
}

vaddr += clen;
len -= clen;
Expand Down

0 comments on commit 7fcdd10

Please sign in to comment.