diff options
author | Alan Modra <amodra@gmail.com> | 2025-02-27 20:53:43 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2025-03-04 08:23:16 +1030 |
commit | 7166166ec098b998dbd48e90be40ce880f7d46de (patch) | |
tree | 4b557ce47a1c4ebd8f7d1ac08fa30fcfbffc8417 | |
parent | 11b6914ce6e680d836dfb711ed7d787113c4c656 (diff) | |
download | binutils-7166166ec098b998dbd48e90be40ce880f7d46de.zip binutils-7166166ec098b998dbd48e90be40ce880f7d46de.tar.gz binutils-7166166ec098b998dbd48e90be40ce880f7d46de.tar.bz2 |
rescoff: ensure file is PE
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.
-rw-r--r-- | binutils/rescoff.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/binutils/rescoff.c b/binutils/rescoff.c index 200d0a3..f9a1e70 100644 --- a/binutils/rescoff.c +++ b/binutils/rescoff.c @@ -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")); |