bfd/
authorJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 20 Jul 2011 19:22:30 +0000 (19:22 +0000)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 20 Jul 2011 19:22:30 +0000 (19:22 +0000)
Fix false coff-go32-exe matches.
* coff-i386.c (TARGET_SYM) <_bfd_check_format>: Conditionally use
COFF_CHECK_FORMAT.
* coff-stgo32.c (go32_check_format): New forward declaration.
(COFF_CHECK_FORMAT): New defintion.
(go32_check_format): New function.

bfd/ChangeLog
bfd/coff-i386.c
bfd/coff-stgo32.c

index 2540c6596a3190f6f72f9c1ddaec2b1741a7c1a8..97594a66deb16f3d4de552f34e6b460369ed528a 100644 (file)
@@ -1,3 +1,12 @@
+2011-07-20  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       Fix false coff-go32-exe matches.
+       * coff-i386.c (TARGET_SYM) <_bfd_check_format>: Conditionally use
+       COFF_CHECK_FORMAT.
+       * coff-stgo32.c (go32_check_format): New forward declaration.
+       (COFF_CHECK_FORMAT): New defintion.
+       (go32_check_format): New function.
+
 2011-07-15  Alan Modra  <amodra@gmail.com>
 
        * configure.in: Bump version.
index 425a0c197676bec2db24548ee6ca74b4777de555..2f17a556505e08b1c87db9b6bea58dbad7f7a8b0 100644 (file)
@@ -671,8 +671,13 @@ const bfd_target
      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
 
 /* Note that we allow an object file to be treated as a core file as well.  */
-    {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
-       bfd_generic_archive_p, coff_object_p},
+    /* bfd_check_format */
+#ifdef COFF_CHECK_FORMAT
+    {_bfd_dummy_target, COFF_CHECK_FORMAT,
+       bfd_generic_archive_p, COFF_CHECK_FORMAT},
+#else
+    {_bfd_dummy_target, coff_object_p, bfd_generic_archive_p, coff_object_p},
+#endif
     {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
        bfd_false},
     {bfd_false, coff_write_object_contents, /* bfd_write_contents */
index e0038cc94ad18259144097edd213a4c3cce3f0ee..c10194e6be85ecea35329bdfa38f2ba4c74fa347 100644 (file)
@@ -95,6 +95,10 @@ create_go32_stub PARAMS ((bfd *));
 #define COFF_ADJUST_AUX_OUT_PRE adjust_aux_out_pre
 #define COFF_ADJUST_AUX_OUT_POST adjust_aux_out_post
 
+static const bfd_target *go32_check_format (bfd *abfd);
+
+#define COFF_CHECK_FORMAT go32_check_format
+
 static bfd_boolean
   go32_stubbed_coff_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
 
@@ -414,3 +418,23 @@ go32_stubbed_coff_bfd_copy_private_bfd_data  (ibfd, obfd)
 
   return TRUE;
 }
+
+/* coff_object_p only checks 2 bytes F_MAGIC at GO32_STUBSIZE inside the file
+   which is too fragile.  */
+
+static const bfd_target *
+go32_check_format (bfd *abfd)
+{
+  char mz[2];
+
+  if (bfd_bread (mz, 2, abfd) != 2 || mz[0] != 'M' || mz[1] != 'Z')
+    {
+      bfd_set_error (bfd_error_wrong_format);
+      return NULL;
+    }
+
+  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
+    return NULL;
+
+  return coff_object_p (abfd);
+}