aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2018-11-03 15:03:34 -0700
committerH.J. Lu <hjl.tools@gmail.com>2018-11-03 15:06:49 -0700
commit675accbdcb5b50182a10dd112b7179b5b6337191 (patch)
treeb89f7ffa83c1a98588c21e38816cdee9f77c5d2f /binutils
parent470678d7c92df4c016c6b4d8dadbd5d5e86cb5ff (diff)
downloadgdb-675accbdcb5b50182a10dd112b7179b5b6337191.zip
gdb-675accbdcb5b50182a10dd112b7179b5b6337191.tar.gz
gdb-675accbdcb5b50182a10dd112b7179b5b6337191.tar.bz2
elfedit: Move ELF header magic bytes check to get_file_header
Skip the file if ELF header magic bytes doesn't match. * elfedit.c (update_elf_header): Move EI_MAG? check to ... (get_file_header): Here.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/ChangeLog5
-rw-r--r--binutils/elfedit.c19
2 files changed, 11 insertions, 13 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 1947569..bdbee0f 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-03 H.J. Lu <hongjiu.lu@intel.com>
+
+ * elfedit.c (update_elf_header): Move EI_MAG? check to ...
+ (get_file_header): Here.
+
2018-11-02 H.J. Lu <hongjiu.lu@intel.com>
* configure.ac (AC_FUNC_MMAP): New.
diff --git a/binutils/elfedit.c b/binutils/elfedit.c
index 5ad846e..a9f7c9d 100644
--- a/binutils/elfedit.c
+++ b/binutils/elfedit.c
@@ -91,17 +91,6 @@ update_elf_header (const char *file_name, FILE *file)
{
int class, machine, type, status, osabi;
- if (elf_header.e_ident[EI_MAG0] != ELFMAG0
- || elf_header.e_ident[EI_MAG1] != ELFMAG1
- || elf_header.e_ident[EI_MAG2] != ELFMAG2
- || elf_header.e_ident[EI_MAG3] != ELFMAG3)
- {
- error
- (_("%s: Not an ELF file - wrong magic bytes at the start\n"),
- file_name);
- return 0;
- }
-
if (elf_header.e_ident[EI_VERSION] != EV_CURRENT)
{
error
@@ -212,6 +201,12 @@ get_file_header (FILE * file)
if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
return 0;
+ if (elf_header.e_ident[EI_MAG0] != ELFMAG0
+ || elf_header.e_ident[EI_MAG1] != ELFMAG1
+ || elf_header.e_ident[EI_MAG2] != ELFMAG2
+ || elf_header.e_ident[EI_MAG3] != ELFMAG3)
+ return 0;
+
/* Determine how to read the rest of the header. */
switch (elf_header.e_ident[EI_DATA])
{
@@ -232,8 +227,6 @@ get_file_header (FILE * file)
switch (elf_header.e_ident[EI_CLASS])
{
default:
- error (_("Unsupported EI_CLASS: %d\n"),
- elf_header.e_ident[EI_CLASS]);
return 0;
case ELFCLASS32: