From Robin Kirkham <Robin.Kirkham@mlb.dmt.csiro.au>:
[deliverable/binutils-gdb.git] / bfd / elf.c
index 602de954309382387d938359e6cd1ebd69bfdef8..88bdaf9ed9660b0e0220f81c1646518610856541 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -305,6 +305,18 @@ bfd_elf_string_from_elf_section (abfd, shindex, strindex)
       && bfd_elf_get_str_section (abfd, shindex) == NULL)
     return NULL;
 
+  if (strindex >= hdr->sh_size)
+    {
+      (*_bfd_error_handler)
+       ("%s: invalid string offset %u >= %lu for section `%s'",
+        bfd_get_filename (abfd), strindex, (unsigned long) hdr->sh_size,
+        ((shindex == elf_elfheader(abfd)->e_shstrndx
+          && strindex == hdr->sh_name)
+         ? ".shstrtab"
+         : elf_string_from_elf_strtab (abfd, hdr->sh_name)));
+      return "";
+    }
+
   return ((char *) hdr->contents) + strindex;
 }
 
@@ -749,7 +761,7 @@ bfd_elf_print_symbol (abfd, filep, symbol, how)
              version_string = "";
            else if (vernum == 1)
              version_string = "Base";
-           else if (vernum < elf_tdata (abfd)->cverdefs)
+           else if (vernum <= elf_tdata (abfd)->cverdefs)
              version_string =
                elf_tdata (abfd)->verdef[vernum - 1].vd_nodename;
            else
@@ -775,13 +787,13 @@ bfd_elf_print_symbol (abfd, filep, symbol, how)
              }
 
            if ((((elf_symbol_type *) symbol)->version & VERSYM_HIDDEN) == 0)
-             fprintf (file, " %-12s", version_string);
+             fprintf (file, "  %-11s", version_string);
            else
              {
                int i;
 
                fprintf (file, " (%s)", version_string);
-               for (i = strlen (version_string) - 10; i > 0; --i)
+               for (i = 10 - strlen (version_string); i > 0; --i)
                  putc (' ', file);
              }
          }
@@ -2106,7 +2118,7 @@ map_sections_to_segments (abfd)
          new_segment = true;
        }
       else if (BFD_ALIGN (last_hdr->lma + last_hdr->_raw_size, maxpagesize)
-              < hdr->lma)
+              < BFD_ALIGN (hdr->lma, maxpagesize))
        {
          /* If putting this section in this segment would force us to
              skip a page in the segment, then we need a new segment.  */
@@ -2860,19 +2872,19 @@ prep_headers (abfd)
 /* end-sanitize-d30v */
 /* start-sanitize-v850 */
     case bfd_arch_v850:
-      i_ehdrp->e_machine = EM_CYGNUS_V850;
+      switch (bfd_get_mach (abfd))
+       {
+       default:
+       case 0:               i_ehdrp->e_machine = EM_CYGNUS_V850; break;
+       }
       break;
 /* end-sanitize-v850 */
-/* start-sanitize-arc */
-    case bfd_arch_arc:
+   case bfd_arch_arc:
       i_ehdrp->e_machine = EM_CYGNUS_ARC;
       break;
-/* end-sanitize-arc */
-/* start-sanitize-m32r */
     case bfd_arch_m32r:
       i_ehdrp->e_machine = EM_CYGNUS_M32R;
       break;
-/* end-sanitize-m32r */
     case bfd_arch_mn10200:
       i_ehdrp->e_machine = EM_CYGNUS_MN10200;
       break;
@@ -3164,7 +3176,7 @@ copy_private_bfd_data (ibfd, obfd)
       m = ((struct elf_segment_map *)
           bfd_alloc (obfd,
                      (sizeof (struct elf_segment_map)
-                      + (csecs - 1) * sizeof (asection *))));
+                      + ((size_t) csecs - 1) * sizeof (asection *))));
       if (m == NULL)
        return false;
 
This page took 0.026468 seconds and 4 git commands to generate.