public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] Sanity check coff-sh and coff-mcore sym string offset
@ 2023-03-21 22:48 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-03-21 22:48 UTC (permalink / raw)
  To: bfd-cvs

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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-21 22:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-21 22:48 [binutils-gdb] Sanity check coff-sh and coff-mcore sym string offset Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).