1 |
/* dl.c - arch-dependent part of loadable module support */ |
/* dl.c - arch-dependent part of loadable module support */ |
2 |
/* |
/* |
3 |
* GRUB -- GRand Unified Bootloader |
* GRUB -- GRand Unified Bootloader |
4 |
* Copyright (C) 2002, 2004 Free Software Foundation, Inc. |
* Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. |
5 |
* |
* |
6 |
* GRUB is free software; you can redistribute it and/or modify |
* GRUB is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
24 |
#include <grub/err.h> |
#include <grub/err.h> |
25 |
|
|
26 |
/* Check if EHDR is a valid ELF header. */ |
/* Check if EHDR is a valid ELF header. */ |
27 |
int |
grub_err_t |
28 |
grub_arch_dl_check_header (void *ehdr, grub_size_t size) |
grub_arch_dl_check_header (void *ehdr) |
29 |
{ |
{ |
30 |
Elf32_Ehdr *e = ehdr; |
Elf32_Ehdr *e = ehdr; |
31 |
|
|
|
/* Check the header size. */ |
|
|
if (size < sizeof (Elf32_Ehdr)) |
|
|
return 0; |
|
|
|
|
32 |
/* Check the magic numbers. */ |
/* Check the magic numbers. */ |
33 |
if (!((e->e_ident[EI_MAG0] == ELFMAG0) |
if (e->e_ident[EI_CLASS] != ELFCLASS32 |
34 |
&& (e->e_ident[EI_MAG1] == ELFMAG1) |
|| e->e_ident[EI_DATA] != ELFDATA2MSB |
35 |
&& (e->e_ident[EI_MAG2] == ELFMAG2) |
|| e->e_machine != EM_PPC) |
36 |
&& (e->e_ident[EI_MAG3] == ELFMAG3) |
return grub_error (GRUB_ERR_BAD_OS, "invalid arch specific ELF magic"); |
|
&& (e->e_ident[EI_CLASS] == ELFCLASS32) |
|
|
&& (e->e_ident[EI_DATA] == ELFDATA2MSB) |
|
|
&& (e->e_ident[EI_VERSION] == EV_CURRENT) |
|
|
&& (e->e_type == ET_REL) && (e->e_machine == EM_PPC) |
|
|
&& (e->e_version == EV_CURRENT))) |
|
|
return 0; |
|
|
|
|
|
/* Make sure that every section is within the core. */ |
|
|
if (size < e->e_shoff + e->e_shentsize * e->e_shnum) |
|
|
return 0; |
|
37 |
|
|
38 |
return 1; |
return GRUB_ERR_NONE; |
39 |
} |
} |
40 |
|
|
41 |
|
|