windres: don't exit so much on errors in read_coff_rsrc

windres code has the habit of exiting on any error.  That's not so
bad, but it does make oss-fuzz ineffective when testing windres.  Fix
many places that print errors and exit to instead print the error and
pass status up the call chain.  In the process of doing this, I
noticed write_res_file was calling bfd_close without checking return
status.  Fixing that resulted in lots of testsuite failures.  The
problem was a lack of bfd_set_format in windres_open_as_binary, which
leaves the output file as bfd_unknown format.  As it happens this
doesn't make any difference in writing the output binary file, except
for the bfd_close return status.
This commit is contained in:
Alan Modra
2025-04-14 19:11:53 +09:30
parent 4846e543de
commit 9e68cae4fd
6 changed files with 549 additions and 180 deletions

View File

@@ -35,9 +35,9 @@ extern int verbose;
extern rc_res_directory *read_rc_file (const char *, const char *, const char *, int, int);
extern rc_res_directory *read_res_file (const char *);
extern rc_res_directory *read_coff_rsrc (const char *, const char *);
extern void write_rc_file (const char *, const rc_res_directory *);
extern void write_res_file (const char *, const rc_res_directory *);
extern void write_coff_file (const char *, const char *, const rc_res_directory *);
extern bool write_rc_file (const char *, const rc_res_directory *);
extern bool write_res_file (const char *, const rc_res_directory *);
extern bool write_coff_file (const char *, const char *, const rc_res_directory *);
extern rc_res_resource *bin_to_res (windres_bfd *, rc_res_id, const bfd_byte *,
rc_uint_type);