elfedit: Move ELF header magic bytes check to get_file_header
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 3 Nov 2018 22:03:34 +0000 (15:03 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 3 Nov 2018 22:06:49 +0000 (15:06 -0700)
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.

binutils/ChangeLog
binutils/elfedit.c

index 19475697b3b151491d3b444aeb084c63888c5551..bdbee0fff63d4bea863296a7d28c2079b3a4300d 100644 (file)
@@ -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.
index 5ad846eb1add2aea7f8764d4c025b62fd1021f5c..a9f7c9d8450493ec4eecf5b4e92b3f6b937c3607 100644 (file)
@@ -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:
This page took 0.026018 seconds and 4 git commands to generate.