Ensure coff-ppc local symbols are zero terminated
authorChen Gang <gang.chen.5i5j@gmail.com>
Thu, 7 Aug 2014 06:06:36 +0000 (15:36 +0930)
committerAlan Modra <amodra@gmail.com>
Thu, 7 Aug 2014 06:11:46 +0000 (15:41 +0930)
* coff-ppc.c (coff_ppc_relocate_section): Ensure local symbols are
zero terminated.

bfd/ChangeLog
bfd/coff-ppc.c

index edbcffa6e7984fff44456943cb8a26923369bfc5..d85f409da888a79cff89efd4bebf6e82e7902c22 100644 (file)
@@ -1,3 +1,8 @@
+2014-08-07  Chen Gang <gang.chen.5i5j@gmail.com>
+
+       * coff-ppc.c (coff_ppc_relocate_section): Ensure local symbols are
+       zero terminated.
+
 2014-08-07  H.J. Lu  <hongjiu.lu@intel.com>
            Alan Modra  <amodra@gmail.com>
 
index 3c39afae7a86b2dad00ec42e8186ca9c7a1aeb0c..32d30120d45a261b125e660c95173caa1490ebd8 100644 (file)
@@ -1073,10 +1073,11 @@ coff_ppc_relocate_section (bfd *output_bfd,
              {
                /* It is a file local symbol.  */
                int *local_toc_table;
-               const char *name;
+               char name[SYMNMLEN + 1];
 
                sym = syms + symndx;
-               name = sym->_n._n_name;
+               strncpy (name, sym->_n._n_name, SYMNMLEN);
+               name[SYMNMLEN] = '\0';
 
                local_toc_table = obj_coff_local_toc_table(input_bfd);
                our_toc_offset = local_toc_table[symndx];
@@ -1225,9 +1226,14 @@ coff_ppc_relocate_section (bfd *output_bfd,
        case IMAGE_REL_PPC_ABSOLUTE:
          {
            const char *my_name;
+           char buf[SYMNMLEN + 1];
 
            if (h == 0)
-             my_name = (syms+symndx)->_n._n_name;
+             {
+               strncpy (buf, (syms+symndx)->_n._n_name, SYMNMLEN);
+               buf[SYMNMLEN] = '\0';
+               my_name = buf;
+             }
            else
              my_name = h->root.root.root.string;
 
@@ -1288,11 +1294,8 @@ coff_ppc_relocate_section (bfd *output_bfd,
              }
 
            if (h == 0)
-             {
-               /* It is a file local symbol.  */
-               sym = syms + symndx;
-               name = sym->_n._n_name;
-             }
+             /* It is a file local symbol.  */
+             sym = syms + symndx;
            else
              {
                char *target = 0;