[binutils-gdb] Sanity check coff-sh and coff-mcore sym string offset
Alan Modra
amodra@sourceware.org
Tue Mar 21 22:48:50 GMT 2023
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4d5b27b30b06cbe3fb8103a323c35970925ccffd
commit 4d5b27b30b06cbe3fb8103a323c35970925ccffd
Author: Alan Modra <amodra@gmail.com>
Date: Wed Mar 22 09:06:48 2023 +1030
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:
---
bfd/coff-mcore.c | 8 +++++++-
bfd/coff-sh.c | 7 ++++++-
2 files changed, 13 insertions(+), 2 deletions(-)
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);
More information about the Binutils-cvs
mailing list