]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
rescoff: ensure file is PE
authorAlan Modra <amodra@gmail.com>
Thu, 27 Feb 2025 10:23:43 +0000 (20:53 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 3 Mar 2025 21:53:16 +0000 (08:23 +1030)
read_coff_rsrc makes one check on object file contents, the existence
of a .rsrc section.  It doesn't check that the file is PE but blindly
accesses bfd pe_data.  Fix that by adding the necessary checks.
Also, the "resources nest too deep" error isn't an overrun, ie. the
"address out of bounds" message isn't correct.  Fix that too.

binutils/rescoff.c

index 200d0a3988c2cc883a3c098ae3416f799a0e81e7..f9a1e70d162eb35d33876356c7edb46648d23ed1 100644 (file)
@@ -133,6 +133,9 @@ read_coff_rsrc (const char *filename, const char *target)
        list_matching_formats (matching);
       xexit (1);
     }
+  if (bfd_get_flavour (abfd) != bfd_target_coff_flavour
+      || !obj_pe (abfd))
+    fatal (_("%s: not a PE file"), filename);
 
   sec = bfd_get_section_by_name (abfd, ".rsrc");
   if (sec == NULL)
@@ -196,7 +199,7 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
      Microsoft only defines 3 levels.  Corrupt files however might
      claim to use more.  */
   if (level > 4)
-    overrun (flaginfo, _("Resources nest too deep"));
+    fatal (_("%s: resources nest too deep"), flaginfo->filename);
 
   if ((size_t) (flaginfo->data_end - data) < sizeof (struct extern_res_directory))
     overrun (flaginfo, _("directory"));