From: Alan Modra Date: Tue, 21 Mar 2023 22:36:48 +0000 (+1030) Subject: Sanity check coff-sh and coff-mcore sym string offset X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4d5b27b30b06cbe3fb8103a323c35970925ccffd;p=binutils-gdb.git Sanity check coff-sh and coff-mcore sym string offset * coff-mcore.c (coff_mcore_relocate_section): Sanity check sym string offset when setting up name for use by error messages. * coff-sh.c (sh_relocate_section): Likewise. --- diff --git a/bfd/coff-mcore.c b/bfd/coff-mcore.c index e360d5efe14..96a1c9d44bc 100644 --- a/bfd/coff-mcore.c +++ b/bfd/coff-mcore.c @@ -434,7 +434,13 @@ coff_mcore_relocate_section (bfd * output_bfd, my_name = "*unknown*"; else if ( sym->_n._n_n._n_zeroes == 0 && sym->_n._n_n._n_offset != 0) - my_name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset; + { + if (sym->_n._n_n._n_offset < obj_coff_strings_len (input_bfd)) + my_name = (obj_coff_strings (input_bfd) + + sym->_n._n_n._n_offset); + else + my_name = "?"; + } else { strncpy (buf, sym->_n._n_name, SYMNMLEN); diff --git a/bfd/coff-sh.c b/bfd/coff-sh.c index 50e9043993b..14f502e3638 100644 --- a/bfd/coff-sh.c +++ b/bfd/coff-sh.c @@ -2866,7 +2866,12 @@ sh_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, name = NULL; else if (sym->_n._n_n._n_zeroes == 0 && sym->_n._n_n._n_offset != 0) - name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset; + { + if (sym->_n._n_n._n_offset < obj_coff_strings_len (input_bfd)) + name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset; + else + name = "?"; + } else { strncpy (buf, sym->_n._n_name, SYMNMLEN);