Fix address violation when attempting to display disassembled data.
authorNick Clifton <nickc@redhat.com>
Mon, 19 Jun 2017 14:57:19 +0000 (15:57 +0100)
committerNick Clifton <nickc@redhat.com>
Mon, 19 Jun 2017 14:57:19 +0000 (15:57 +0100)
PR binutils/21619
* objdump.c (disassemble_bytes): Check that there is sufficient
data available before attempting to display it.

binutils/ChangeLog
binutils/objdump.c

index 0766e670709477ccd2d39d690dcb05707ae0892e..6997db969c1fb116f4f101066aeb8ea58525b432 100644 (file)
@@ -1,3 +1,9 @@
+2017-06-19  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/21619
+       * objdump.c (disassemble_bytes): Check that there is sufficient
+       data available before attempting to display it.
+
 2017-06-06  Simon Marchi  <simon.marchi@ericsson.com>
 
        * sysinfo.y: Free memory allocated by token NAME.
index 05402edbebf52f44845518b7be82c3acff76233c..16e1f0ea9fa3f70584f2655d600d503d98c74d0d 100644 (file)
@@ -1982,20 +1982,23 @@ disassemble_bytes (struct disassemble_info * inf,
                    pb = octets;
                  for (; j < addr_offset * opb + pb; j += bpc)
                    {
-                     int k;
-
-                     if (bpc > 1 && inf->display_endian == BFD_ENDIAN_LITTLE)
+                     /* PR 21619: Check for a buffer ending early.  */
+                     if (j + bpc <= stop_offset * opb)
                        {
-                         for (k = bpc - 1; k >= 0; k--)
-                           printf ("%02x", (unsigned) data[j + k]);
-                         putchar (' ');
-                       }
-                     else
-                       {
-                         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 (' ');
                    }
                }
            }