* kern/elf.c (grub_elf_file): Call grub_file_seek. Call
grub_error_push and grub_error_pop in the error-handling path.
(grub_elf32_load_segment): Only call grub_file_read with non-zero
length.
+2006-11-03 Hollis Blanchard <hollis@penguinppc.org>
+
+ * kern/elf.c (grub_elf_file): Call grub_file_seek. Call
+ grub_error_push and grub_error_pop in the error-handling path.
+ (grub_elf32_load_segment): Only call grub_file_read with non-zero
+ length.
+
2006-11-03 Hollis Blanchard <hollis@penguinppc.org>
* conf/i386-efi.rmk (grub_emu_SOURCES): Add kern/elf.c.
elf->file = file;
elf->phdrs = 0;
+ if (grub_file_seek (elf->file, 0) == (grub_off_t) -1)
+ goto fail;
+
if (grub_file_read (elf->file, (char *) &elf->ehdr, sizeof (elf->ehdr))
!= sizeof (elf->ehdr))
{
return elf;
fail:
+ grub_error_push ();
grub_elf_close (elf);
+ grub_error_pop ();
return 0;
}
return grub_error (GRUB_ERR_BAD_OS, "Invalid offset in program header");
}
- if (grub_file_read (elf->file, (void *) load_addr, phdr->p_filesz)
+ if (phdr->p_filesz
+ && grub_file_read (elf->file, (void *) load_addr, phdr->p_filesz)
!= (grub_ssize_t) phdr->p_filesz)
{
return grub_error (GRUB_ERR_BAD_OS, "Couldn't load segment");