diff --git a/ChangeLog b/ChangeLog index 6ff44f6b0..9c808c52c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-11-03 Hollis Blanchard + + * 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 * conf/i386-efi.rmk (grub_emu_SOURCES): Add kern/elf.c. diff --git a/kern/elf.c b/kern/elf.c index 02619dd87..df78dade4 100644 --- a/kern/elf.c +++ b/kern/elf.c @@ -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");