Sanity check coff-sh and coff-mcore sym string offset
authorAlan Modra <amodra@gmail.com>
Tue, 21 Mar 2023 22:36:48 +0000 (09:06 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 21 Mar 2023 22:36:48 +0000 (09:06 +1030)
* 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.

bfd/coff-mcore.c
bfd/coff-sh.c

index e360d5efe140bcb492fe5d11dcdce14d90dbf4f4..96a1c9d44bca2b9f66b1f3364e6505bec714cbef 100644 (file)
@@ -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);
index 50e9043993b41353b01fa2bffcb81fc2d0353fd4..14f502e363818877c5939a722d4133d4faa0ded1 100644 (file)
@@ -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);