Fix seg-fault running strip on a corrupt binary.
[deliverable/binutils-gdb.git] / bfd / pei-x86_64.c
index 16d88997e4628d89d58816638ad806d6f93a334a..1e628c87f0ab7191fdd53c1ef4bea22a7dc2b4b4 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD back-end for Intel 386 PE IMAGE COFF files.
-   Copyright (C) 2006-2014 Free Software Foundation, Inc.
+   Copyright (C) 2006-2016 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -346,7 +346,7 @@ pex64_dump_xdata (FILE *file, bfd *abfd,
     end_addr = sec_size;
 
   pex64_get_unwind_info (abfd, &ui, &xdata[addr]);
-  
+
   if (ui.Version != 1 && ui.Version != 2)
     {
       unsigned int i;
@@ -487,6 +487,7 @@ pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section)
   stop = pei_section_data (abfd, pdata_section)->virt_size;
   if ((stop % onaline) != 0)
     fprintf (file,
+            /* xgettext:c-format */
             _("Warning: %s section size (%ld) is not a multiple of %d\n"),
             pdata_section->name, (long) stop, onaline);
 
@@ -508,8 +509,10 @@ pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section)
   else if (datasize < stop)
       {
        fprintf (file,
+                /* xgettext:c-format */
                 _("Warning: %s section size (%ld) is smaller than virtual size (%ld)\n"),
-                pdata_section->name, datasize, stop);
+                pdata_section->name, (unsigned long) datasize,
+                (unsigned long) stop);
        /* Be sure not to read passed datasize.  */
        stop = datasize / onaline;
       }
@@ -600,14 +603,16 @@ pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section)
      section name, replacing .pdata by .xdata prefix.  */
   if (strcmp (pdata_section->name, ".pdata") != 0)
     {
-      char *xdata_name = alloca (strlen (pdata_section->name + 1));
+      size_t len = strlen (pdata_section->name);
+      char *xdata_name = xmalloc (len + 1);
 
-      xdata_name = strcpy (xdata_name, pdata_section->name);
+      xdata_name = memcpy (xdata_name, pdata_section->name, len + 1);
       /* Transform .pdata prefix into .xdata prefix.  */
-      if (strlen (xdata_name) > 1)
+      if (len > 1)
        xdata_name [1] = 'x';
       xdata_section = pex64_get_section_by_rva (abfd, xdata_base,
                                                xdata_name);
+      free (xdata_name);
     }
   /* Second, try the .xdata section itself.  */
   if (!xdata_section)
This page took 0.024209 seconds and 4 git commands to generate.