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.
This commit is contained in:
hollisb 2006-11-03 23:05:14 +00:00
parent 8b55db6631
commit ae4f23bfa6
2 changed files with 14 additions and 1 deletions

View File

@ -1,3 +1,10 @@
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.

View File

@ -69,6 +69,9 @@ grub_elf_file (grub_file_t file)
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))
{
@ -82,7 +85,9 @@ grub_elf_file (grub_file_t file)
return elf;
fail:
grub_error_push ();
grub_elf_close (elf);
grub_error_pop ();
return 0;
}
@ -129,7 +134,8 @@ grub_elf32_load_segment (grub_elf_t elf, Elf32_Phdr *phdr, void *hook)
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");