diff --git a/ChangeLog b/ChangeLog index 228603524..3acd07f97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +2011-12-26 Vladimir Serbinenko + + Don't override more informative errors. + + * grub-core/commands/acpi.c (grub_cmd_acpi): Don't override errors. + * grub-core/font/font.c (open_section): Likewise. + * grub-core/loader/i386/bsd.c (grub_bsd_load_aout): New argument + filename. Don't override errors. + (grub_cmd_openbsd_ramdisk): Don't override errors. + * grub-core/loader/i386/linux.c (grub_cmd_linux): Likewise. + (grub_cmd_initrd): Likewise. + * grub-core/loader/i386/pc/linux.c (grub_cmd_linux): Likewise. + (grub_cmd_initrd): Likewise. + * grub-core/loader/ia64/efi/linux.c (grub_load_elf64): Likewise. + (grub_cmd_linux): Likewise. + (grub_cmd_initrd): Likewise. + (grub_cmd_payload): Likewise. + * grub-core/loader/mips/linux.c (grub_cmd_initrd): Likewise. + * grub-core/loader/multiboot.c (grub_cmd_multiboot): Likewise. + (grub_cmd_module): Likewise. + * grub-core/loader/powerpc/ieee1275/linux.c (grub_cmd_initrd): Likewise. + * grub-core/loader/sparc64/ieee1275/linux.c (grub_cmd_initrd): Likewise. + * grub-core/loader/xnu.c (grub_xnu_load_driver): Likewise. + (grub_cmd_xnu_mkext): Likewise. + (grub_cmd_xnu_ramdisk): Likewise. + (grub_xnu_check_os_bundle_required): Likewise. + (grub_xnu_load_kext_from_dir): Likewise. + (grub_cmd_xnu_kextdir): Likewise. + * grub-core/loader/xnu_resume.c (grub_xnu_resume): Likewise. + 2011-12-25 Vladimir Serbinenko * grub-core/fs/minix.c (grub_minix_mount) [MODE_MINIX3]: Treat 0xffff diff --git a/grub-core/commands/acpi.c b/grub-core/commands/acpi.c index 2531b8e11..048f8c0cb 100644 --- a/grub-core/commands/acpi.c +++ b/grub-core/commands/acpi.c @@ -649,15 +649,17 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args) { grub_file_close (file); free_tables (); - return grub_error (GRUB_ERR_OUT_OF_MEMORY, - "couldn't read file %s", args[i]); + return grub_errno; } if (grub_file_read (file, buf, size) != (int) size) { grub_file_close (file); free_tables (); - return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[i]); + if (!grub_errno) + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), + args[i]); + return grub_errno; } grub_file_close (file); diff --git a/grub-core/font/font.c b/grub-core/font/font.c index 3737480cf..8d74534ef 100644 --- a/grub-core/font/font.c +++ b/grub-core/font/font.c @@ -250,8 +250,7 @@ open_section (grub_file_t file, struct font_file_section *section) } else if (retval < 0) { - grub_error (GRUB_ERR_BAD_FONT, - "font format error: can't read section name"); + /* Read error. */ return 1; } @@ -265,8 +264,7 @@ open_section (grub_file_t file, struct font_file_section *section) } else if (retval < 0) { - grub_error (GRUB_ERR_BAD_FONT, - "font format error: can't read section length"); + /* Read error. */ return 1; } diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c index f9bab21e6..835f14695 100644 --- a/grub-core/loader/i386/bsd.c +++ b/grub-core/loader/i386/bsd.c @@ -1159,7 +1159,7 @@ grub_bsd_unload (void) } static grub_err_t -grub_bsd_load_aout (grub_file_t file) +grub_bsd_load_aout (grub_file_t file, const char *filename) { grub_addr_t load_addr, load_end; int ofs, align_page; @@ -1171,7 +1171,12 @@ grub_bsd_load_aout (grub_file_t file) return grub_errno; if (grub_file_read (file, &ah, sizeof (ah)) != sizeof (ah)) - return grub_error (GRUB_ERR_READ_ERROR, "cannot read the a.out header"); + { + if (!grub_errno) + grub_error (GRUB_ERR_READ_ERROR, N_("premature end of file %s"), + filename); + return grub_errno; + } if (grub_aout_get_type (&ah) != AOUT_TYPE_AOUT32) return grub_error (GRUB_ERR_BAD_OS, "invalid a.out header"); @@ -1426,7 +1431,7 @@ grub_bsd_load (int argc, char *argv[]) { is_elf_kernel = 0; grub_errno = 0; - grub_bsd_load_aout (file); + grub_bsd_load_aout (file, argv[0]); grub_file_close (file); } @@ -2000,8 +2005,7 @@ grub_cmd_openbsd_ramdisk (grub_command_t cmd __attribute__ ((unused)), file = grub_file_open (args[0]); if (! file) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, - "couldn't load ramdisk"); + return grub_errno; size = grub_file_size (file); @@ -2017,8 +2021,9 @@ grub_cmd_openbsd_ramdisk (grub_command_t cmd __attribute__ ((unused)), != (grub_ssize_t) (size)) { grub_file_close (file); - grub_error_push (); - return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]); + if (!grub_errno) + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]); + return grub_errno; } grub_memset (openbsd_ramdisk.target + size, 0, openbsd_ramdisk.max_size - size); diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 80ad542e3..1f89ec5d2 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -649,7 +649,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) { - grub_error (GRUB_ERR_READ_ERROR, "cannot read the Linux header"); + if (!grub_errno) + grub_error (GRUB_ERR_READ_ERROR, N_("premature end of file %s"), + argv[0]); goto fail; } @@ -717,7 +719,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), len = 0x400 - sizeof (lh); if (grub_file_read (file, (char *) real_mode_mem + sizeof (lh), len) != len) { - grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); + if (!grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), + argv[0]); goto fail; } @@ -908,8 +912,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - (sizeof (LINUX_IMAGE) - 1)); len = prot_size; - if (grub_file_read (file, prot_mode_mem, len) != len) - grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); + if (grub_file_read (file, prot_mode_mem, len) != len && !grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), + argv[0]); if (grub_errno == GRUB_ERR_NONE) { @@ -1014,7 +1019,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, initrd_mem, size) != size) { - grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); + if (!grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), + argv[0]); goto fail; } diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c index c7c099174..077b17bb8 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c @@ -108,7 +108,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) { - grub_error (GRUB_ERR_READ_ERROR, "cannot read the Linux header"); + if (!grub_errno) + grub_error (GRUB_ERR_READ_ERROR, N_("premature end of file %s"), + argv[0]); goto fail; } @@ -283,7 +285,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), len = real_size + GRUB_DISK_SECTOR_SIZE - sizeof (lh); if (grub_file_read (file, grub_linux_real_chunk + sizeof (lh), len) != len) { - grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); + if (!grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), + argv[0]); goto fail; } @@ -321,8 +325,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), len = grub_linux16_prot_size; if (grub_file_read (file, grub_linux_prot_chunk, grub_linux16_prot_size) - != (grub_ssize_t) grub_linux16_prot_size) - grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); + != (grub_ssize_t) grub_linux16_prot_size && !grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), + argv[0]); if (grub_errno == GRUB_ERR_NONE) { @@ -424,7 +429,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, initrd_chunk, size) != size) { - grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); + if (!grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), + argv[0]); goto fail; } diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c index 247eebae5..ab28c1dea 100644 --- a/grub-core/loader/ia64/efi/linux.c +++ b/grub-core/loader/ia64/efi/linux.c @@ -30,6 +30,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -377,7 +378,7 @@ grub_linux_unload (void) } static grub_err_t -grub_load_elf64 (grub_file_t file, void *buffer) +grub_load_elf64 (grub_file_t file, void *buffer, const char *filename) { Elf64_Ehdr *ehdr = (Elf64_Ehdr *) buffer; Elf64_Phdr *phdr; @@ -472,11 +473,15 @@ grub_load_elf64 (grub_file_t file, void *buffer) return grub_error (GRUB_ERR_BAD_OS, "invalid offset in program header"); - if (grub_file_read (file, (void *)(phdr->p_paddr + reloc_offset), + if (grub_file_read (file, (void *) (phdr->p_paddr + reloc_offset), phdr->p_filesz) != (grub_ssize_t) phdr->p_filesz) - return grub_error (GRUB_ERR_BAD_OS, - "couldn't read segment from file"); + { + if (!grub_errno) + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), + filename); + return grub_errno; + } if (phdr->p_filesz < phdr->p_memsz) grub_memset @@ -515,13 +520,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), file = grub_file_open (argv[0]); if (! file) - { - grub_error (GRUB_ERR_BAD_ARGUMENT, "Couldn't open file"); - goto fail; - } + goto fail; len = grub_file_read (file, buffer, sizeof (buffer)); - if (len < (grub_ssize_t)sizeof (Elf64_Ehdr)) + if (len < (grub_ssize_t) sizeof (Elf64_Ehdr)) { grub_error (GRUB_ERR_BAD_OS, "File too small"); goto fail; @@ -529,7 +531,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_printf ("Loading linux: %s\n", argv[0]); - if (grub_load_elf64 (file, buffer)) + if (grub_load_elf64 (file, buffer, argv[0])) goto fail; len = sizeof("BOOT_IMAGE=") + 8; @@ -611,9 +613,11 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), (grub_uint64_t)initrd_mem, initrd_size); if (grub_file_read (file, initrd_mem, initrd_size) - != (grub_ssize_t)initrd_size) + != (grub_ssize_t) initrd_size) { - grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file"); + if (!grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), + argv[0]); goto fail; } fail: @@ -659,7 +663,9 @@ grub_cmd_payload (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, base, size) != size) { - grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file"); + if (!grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), + argv[0]); goto fail; } diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index 17c2656e2..739bc0291 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -478,7 +478,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, initrd_src, size) != size) { - grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); + if (!grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), + argv[0]); grub_file_close (file); return grub_errno; diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c index f76123e67..fec1b5bf6 100644 --- a/grub-core/loader/multiboot.c +++ b/grub-core/loader/multiboot.c @@ -226,7 +226,7 @@ grub_cmd_multiboot (grub_command_t cmd __attribute__ ((unused)), file = grub_file_open (argv[0]); if (! file) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file"); + return grub_errno; grub_dl_ref (my_mod); @@ -322,7 +322,10 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, module, size) != size) { grub_file_close (file); - return grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); + if (!grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), + argv[0]); + return grub_errno; } grub_file_close (file); diff --git a/grub-core/loader/powerpc/ieee1275/linux.c b/grub-core/loader/powerpc/ieee1275/linux.c index 12a3fa9f6..c6a5afecf 100644 --- a/grub-core/loader/powerpc/ieee1275/linux.c +++ b/grub-core/loader/powerpc/ieee1275/linux.c @@ -353,7 +353,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, (void *) addr, size) != size) { grub_ieee1275_release (addr, size); - grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); + if (!grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), + argv[0]); goto fail; } diff --git a/grub-core/loader/sparc64/ieee1275/linux.c b/grub-core/loader/sparc64/ieee1275/linux.c index 8ed61f8bf..273dbd61e 100644 --- a/grub-core/loader/sparc64/ieee1275/linux.c +++ b/grub-core/loader/sparc64/ieee1275/linux.c @@ -417,7 +417,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, (void *) addr, size) != size) { - grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file"); + if (!grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), + argv[0]); goto fail; } diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c index f96bc2b75..7da355183 100644 --- a/grub-core/loader/xnu.c +++ b/grub-core/loader/xnu.c @@ -738,9 +738,10 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile) != (grub_ssize_t) (infoplistsize)) { grub_file_close (infoplist); - grub_error_push (); - return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s: ", - infoplistname); + if (!grub_errno) + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s: "), + infoplistname); + return grub_errno; } grub_file_close (infoplist); buf[infoplistsize] = 0; @@ -782,8 +783,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)), file = grub_file_open (args[0]); if (! file) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, - "couldn't load driver package"); + return grub_errno; /* Sometimes caches are fat binary. Errgh. */ if (grub_file_read (file, &head, sizeof (head)) @@ -792,8 +792,9 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)), /* I don't know the internal structure of package but can hardly imagine a valid package shorter than 20 bytes. */ grub_file_close (file); - grub_error_push (); - return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]); + if (!grub_errno) + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]); + return grub_errno; } /* Find the corresponding architecture. */ @@ -804,9 +805,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)), if (! archs) { grub_file_close (file); - grub_error_push (); - return grub_error (GRUB_ERR_OUT_OF_MEMORY, - "couldn't read file %s", args[0]); + return grub_errno; } if (grub_file_read (file, archs, @@ -814,8 +813,10 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)), != (grub_ssize_t) sizeof(struct grub_macho_fat_arch) * narchs) { grub_free (archs); - grub_error_push (); - return grub_error (GRUB_ERR_READ_ERROR, "cannot read fat header"); + if (!grub_errno) + grub_error (GRUB_ERR_READ_ERROR, N_("premature end of file %s"), + args[0]); + return grub_errno; } for (i = 0; i < narchs; i++) { @@ -867,8 +868,9 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)), if (grub_file_read (file, loadto, readlen) != (grub_ssize_t) (readlen)) { grub_file_close (file); - grub_error_push (); - return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]); + if (!grub_errno) + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]); + return grub_errno; } grub_file_close (file); @@ -895,8 +897,7 @@ grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)), file = grub_file_open (args[0]); if (! file) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, - "couldn't load ramdisk"); + return grub_errno; err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE); if (err) @@ -907,12 +908,12 @@ grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)), err = grub_xnu_heap_malloc (size, &loadto, &loadto_target); if (err) return err; - if (grub_file_read (file, loadto, size) - != (grub_ssize_t) (size)) + if (grub_file_read (file, loadto, size) != (grub_ssize_t) (size)) { grub_file_close (file); - grub_error_push (); - return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]); + if (!grub_errno) + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]); + return grub_errno; } return grub_xnu_register_memory ("RAMDisk", 0, loadto_target, size); } @@ -936,27 +937,20 @@ grub_xnu_check_os_bundle_required (char *plistname, file = grub_file_open (plistname); if (! file) - { - grub_file_close (file); - grub_error_push (); - grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", plistname); - return 0; - } + return 0; size = grub_file_size (file); buf = grub_malloc (size); if (! buf) { grub_file_close (file); - grub_error_push (); - grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't read file %s", plistname); return 0; } if (grub_file_read (file, buf, size) != (grub_ssize_t) (size)) { grub_file_close (file); - grub_error_push (); - grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", plistname); + if (!grub_errno) + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), plistname); return 0; } grub_file_close (file); @@ -1150,7 +1144,7 @@ grub_xnu_load_kext_from_dir (char *dirname, const char *osbundlerequired, newdirname = grub_malloc (grub_strlen (dirname) + 20); if (! newdirname) - return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't allocate buffer"); + return grub_errno; grub_strcpy (newdirname, dirname); newdirname[grub_strlen (dirname)] = '/'; newdirname[grub_strlen (dirname) + 1] = 0; @@ -1271,8 +1265,7 @@ grub_cmd_xnu_kextdir (grub_command_t cmd __attribute__ ((unused)), char *osbundlerequired = grub_strdup (args[1]), *ptr; grub_err_t err; if (! osbundlerequired) - return grub_error (GRUB_ERR_OUT_OF_MEMORY, - "couldn't allocate string temporary space"); + return grub_errno; for (ptr = osbundlerequired; *ptr; ptr++) *ptr = grub_tolower (*ptr); err = grub_xnu_scan_dir_for_kexts (args[0], osbundlerequired, 10); diff --git a/grub-core/loader/xnu_resume.c b/grub-core/loader/xnu_resume.c index 8f0e24483..d7f9adaaf 100644 --- a/grub-core/loader/xnu_resume.c +++ b/grub-core/loader/xnu_resume.c @@ -25,6 +25,7 @@ #include #include #include +#include static void *grub_xnu_hibernate_image; @@ -59,11 +60,13 @@ grub_xnu_resume (char *imagename) /* Read the header. */ if (grub_file_read (file, &hibhead, sizeof (hibhead)) - !=sizeof (hibhead)) + != sizeof (hibhead)) { grub_file_close (file); - return grub_error (GRUB_ERR_READ_ERROR, - "cannot read the hibernate header"); + if (!grub_errno) + grub_error (GRUB_ERR_READ_ERROR, + N_("premature end of file %s"), imagename); + return grub_errno; } /* Check the header. */ @@ -138,7 +141,10 @@ grub_xnu_resume (char *imagename) != (grub_ssize_t) codesize) { grub_file_close (file); - return grub_error (GRUB_ERR_READ_ERROR, "cannot read resume image"); + if (!grub_errno) + grub_error (GRUB_ERR_READ_ERROR, + N_("premature end of file %s"), imagename); + return grub_errno; } /* Read image. */ @@ -147,7 +153,10 @@ grub_xnu_resume (char *imagename) != (grub_ssize_t) hibhead.image_size) { grub_file_close (file); - return grub_error (GRUB_ERR_READ_ERROR, "cannot read resume image"); + if (!grub_errno) + grub_error (GRUB_ERR_READ_ERROR, + N_("premature end of file %s"), imagename); + return grub_errno; } grub_file_close (file);