Skip to content

Commit

Permalink
rescoff: ensure file is PE
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amodra committed Mar 3, 2025
1 parent 11b6914 commit 7166166
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion binutils/rescoff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit 7166166

Please sign in to comment.