Fix address violation when disassembling a corrupt binary.
authorNick Clifton <nickc@redhat.com>
Wed, 14 Jun 2017 15:50:03 +0000 (16:50 +0100)
committerNick Clifton <nickc@redhat.com>
Wed, 14 Jun 2017 15:50:03 +0000 (16:50 +0100)
PR binutils/21580
binutils * objdump.c (disassemble_bytes): Check for buffer overrun when
printing out rae insns.

ld * testsuite/ld-nds32/diff.d: Adjust expected output.

binutils/objdump.c
ld/ChangeLog
ld/testsuite/ld-nds32/diff.d

index 6dc8318a5a92f1ac8f36fb29c39b09176c28a253..05402edbebf52f44845518b7be82c3acff76233c 100644 (file)
@@ -1918,20 +1918,23 @@ disassemble_bytes (struct disassemble_info * inf,
 
              for (j = addr_offset * opb; j < addr_offset * opb + pb; j += bpc)
                {
-                 int k;
-
-                 if (bpc > 1 && inf->display_endian == BFD_ENDIAN_LITTLE)
-                   {
-                     for (k = bpc - 1; k >= 0; k--)
-                       printf ("%02x", (unsigned) data[j + k]);
-                     putchar (' ');
-                   }
-                 else
+                 /* PR 21580: Check for a buffer ending early.  */
+                 if (j + bpc <= stop_offset * opb)
                    {
-                     for (k = 0; k < bpc; k++)
-                       printf ("%02x", (unsigned) data[j + k]);
-                     putchar (' ');
+                     int k;
+
+                     if (inf->display_endian == BFD_ENDIAN_LITTLE)
+                       {
+                         for (k = bpc - 1; k >= 0; k--)
+                           printf ("%02x", (unsigned) data[j + k]);
+                       }
+                     else
+                       {
+                         for (k = 0; k < bpc; k++)
+                           printf ("%02x", (unsigned) data[j + k]);
+                       }
                    }
+                 putchar (' ');
                }
 
              for (; pb < octets_per_line; pb += bpc)
index 8d5246424baec9ce17115d57829b2a0eb6c14765..72777eeea96b5d399313740e07370da81173e9ba 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-14  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/21580
+       * testsuite/ld-nds32/diff.d: Adjust expected output.
+
 2017-06-14  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/20022
index ef7958666fecc48ecabe4f9c35c881f8540e6b78..1aff7366def69ffc9166935b27d67d3596816fbb 100644 (file)
@@ -7,9 +7,9 @@
 
 Disassembly of section .data:
 00008000 <WORD> (7e 00 00 00|00 00 00 7e).*
-00008004 <HALF> (7e 00 7e fe|00 7e 7e fe).*
-00008006 <BYTE> 7e fe 00 fe.*
-00008007 <ULEB128> fe 00.*
+00008004 <HALF> (7e 00|00 7e).*
+00008006 <BYTE> 7e.*
+00008007 <ULEB128> fe.*
        ...
 00008009 <ULEB128_2> fe 00.*
 .*