PR27459, segmentation fault in go32exe_check_format
Alan Modra
amodra@gmail.com
Wed Feb 24 02:26:18 GMT 2021
PR 27459
* coff-stgo32.c (go32exe_check_format): Sanity check size of
header to avoid a buffer overflow.
diff --git a/bfd/coff-stgo32.c b/bfd/coff-stgo32.c
index 7ae9419772..7593b62e8e 100644
--- a/bfd/coff-stgo32.c
+++ b/bfd/coff-stgo32.c
@@ -304,7 +304,9 @@ go32exe_check_format (bfd *abfd)
/* Confirm that this is a go32stub. */
header_end = H_GET_16 (abfd, filehdr_dos.e_cparhdr) * 16UL;
- if (! CONST_STRNEQ (go32exe_temp_stub + header_end, "go32stub"))
+ if (go32exe_temp_stub_size < header_end
+ || go32exe_temp_stub_size - header_end < sizeof "go32stub" - 1
+ || !CONST_STRNEQ (go32exe_temp_stub + header_end, "go32stub"))
goto fail_format;
/* Set origin to where the COFF header starts and seek there. */
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list