Fix seg-faults in objdump when disassembling a corrupt versados binary.
authorNick Clifton <nickc@redhat.com>
Wed, 14 Jun 2017 09:35:16 +0000 (10:35 +0100)
committerNick Clifton <nickc@redhat.com>
Wed, 14 Jun 2017 09:35:16 +0000 (10:35 +0100)
PR binutils/21591
* versados.c (versados_mkobject): Zero the allocated tdata structure.
(process_otr): Check for an invalid offset in the otr structure.

bfd/ChangeLog
bfd/versados.c

index 67fd18a102a0834fef957b766527c2466be3cc10..a035ab54e2c55422899fa0727a917ddb90bd1cce 100644 (file)
@@ -1,3 +1,9 @@
+2017-06-14  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/21591
+       * versados.c (versados_mkobject): Zero the allocated tdata structure.
+       (process_otr): Check for an invalid offset in the otr structure.
+
 2017-06-14  Sebastian Huber  <sebastian.huber@embedded-brains.de>
 
        * config.bfd (epiphany-*-elf): Accept epiphany-*-*.
index 2efbcff5e94736a254ed57723b126124826b6bb7..f0c5fdf87d76df76d8cec5c3db6e67b9e1358031 100644 (file)
@@ -149,7 +149,7 @@ versados_mkobject (bfd *abfd)
   if (abfd->tdata.versados_data == NULL)
     {
       bfd_size_type amt = sizeof (tdata_type);
-      tdata_type *tdata = bfd_alloc (abfd, amt);
+      tdata_type *tdata = bfd_zalloc (abfd, amt);
 
       if (tdata == NULL)
        return FALSE;
@@ -345,13 +345,13 @@ reloc_howto_type versados_howto_table[] =
 };
 
 static int
-get_offset (int len, unsigned char *ptr)
+get_offset (unsigned int len, unsigned char *ptr)
 {
   int val = 0;
 
   if (len)
     {
-      int i;
+      unsigned int i;
 
       val = *ptr++;
       if (val & 0x80)
@@ -394,9 +394,13 @@ process_otr (bfd *abfd, struct ext_otr *otr, int pass)
          int flag = *srcp++;
          int esdids = (flag >> 5) & 0x7;
          int sizeinwords = ((flag >> 3) & 1) ? 2 : 1;
-         int offsetlen = flag & 0x7;
+         unsigned int offsetlen = flag & 0x7;
          int j;
 
+         /* PR 21591: Check for invalid lengths.  */
+         if (srcp + esdids + offsetlen >= endp)
+           return;
+
          if (esdids == 0)
            {
              /* A zero esdid means the new pc is the offset given.  */
This page took 0.028095 seconds and 4 git commands to generate.