2005-02-14 Guillem Jover <guillem@hadrons.org>

* include/grub/dl.h (grub_dl_check_header): New prototype.
	(grub_arch_dl_check_header): Change return type to grub_err_t,
	remove size parameter and export function.  Update all callers.
	* kern/dl.c (grub_dl_check_header): New function.
	(grub_dl_load_core): Use `grub_dl_check_header' instead of
	`grub_arch_dl_check_header'.  Check ELF type.  Check if sections
	are inside the core.
	* kern/i386/dl.c (grub_arch_dl_check_header): Remove arch
	independent ELF header checks.
	* kern/powerpc/dl.c (grub_arch_dl_check_header): Likewise.
	* loader/i386/pc/multiboot.c (grub_rescue_cmd_multiboot): Use
	`grub_dl_check_header' instead of explicit checks.  Check for the
	ELF type.
	* loader/powerpc/ieee1275/linux.c (grub_rescue_cmd_linux): Use
	`grub_dl_check_header' instead of explicit checks.  Remove arch
	specific ELF header checks.
This commit is contained in:
marco_g 2005-02-14 18:41:33 +00:00
parent 5eabe94bd9
commit c642636f8a
8 changed files with 86 additions and 86 deletions

View file

@ -1,7 +1,7 @@
/* multiboot.c - boot a multiboot OS image. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -140,20 +140,18 @@ grub_rescue_cmd_multiboot (int argc, char *argv[])
ehdr = (Elf32_Ehdr *) buffer;
if (!((ehdr->e_ident[EI_MAG0] == ELFMAG0)
&& (ehdr->e_ident[EI_MAG1] == ELFMAG1)
&& (ehdr->e_ident[EI_MAG2] == ELFMAG2)
&& (ehdr->e_ident[EI_MAG3] == ELFMAG3)
&& (ehdr->e_ident[EI_CLASS] == ELFCLASS32)
&& (ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
&& (ehdr->e_ident[EI_VERSION] == EV_CURRENT)
&& (ehdr->e_type == ET_EXEC) && (ehdr->e_machine == EM_386)
&& (ehdr->e_version == EV_CURRENT)))
if (grub_dl_check_header (ehdr, sizeof(*ehdr)))
{
grub_error (GRUB_ERR_UNKNOWN_OS, "No valid ELF header found");
goto fail;
}
if (ehdr->e_type != ET_EXEC)
{
grub_error (GRUB_ERR_UNKNOWN_OS, "invalid ELF file type");
goto fail;
}
/* FIXME: Should we support program headers at strange locations? */
if (ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize > GRUB_MB_SEARCH)
{

View file

@ -1,7 +1,7 @@
/* linux.c - boot Linux */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -124,15 +124,7 @@ grub_rescue_cmd_linux (int argc, char *argv[])
goto fail;
}
if (!((ehdr.e_ident[EI_MAG0] == ELFMAG0)
&& (ehdr.e_ident[EI_MAG1] == ELFMAG1)
&& (ehdr.e_ident[EI_MAG2] == ELFMAG2)
&& (ehdr.e_ident[EI_MAG3] == ELFMAG3)
&& (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
&& (ehdr.e_ident[EI_DATA] == ELFDATA2MSB)
&& (ehdr.e_ident[EI_VERSION] == EV_CURRENT)
&& (ehdr.e_type == ET_EXEC) && (ehdr.e_machine == EM_PPC)
&& (ehdr.e_version == EV_CURRENT)))
if (grub_dl_check_header (&ehdr, sizeof(ehdr)))
{
grub_error (GRUB_ERR_UNKNOWN_OS, "No valid ELF header found");
goto fail;
@ -145,20 +137,6 @@ grub_rescue_cmd_linux (int argc, char *argv[])
goto fail;
}
if (ehdr.e_machine != EM_PPC)
{
grub_error (GRUB_ERR_UNKNOWN_OS,
"This ELF file is not for the PPC32\n");
goto fail;
}
if (ehdr.e_version != EV_CURRENT)
{
grub_error (GRUB_ERR_UNKNOWN_OS,
"Invalid ELF version\n");
goto fail;
}
/* Read the sections. */
entry = ehdr.e_entry;
if (entry == 0xc0000000)