Don't read beyond section end
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 7 Nov 2012 06:16:26 +0000 (06:16 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 7 Nov 2012 06:16:26 +0000 (06:16 +0000)
* objcopy.c (copy_section): Don't read beyond section end.

binutils/ChangeLog
binutils/objcopy.c

index 84ea185c4f80bc62439395de4e3600cd2ba65bed..688d569d87dbbb523b3a611162588b1affaa8e41 100644 (file)
@@ -1,3 +1,7 @@
+2012-11-07  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * objcopy.c (copy_section): Don't read beyond section end.
+
 2012-11-06  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR binutils/14567
index f44ebcd942a4f14f9b531e2c13096fd9b424a844..4860864679fb056b0455c7e742af7c2fee9c2693 100644 (file)
@@ -2823,7 +2823,11 @@ copy_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
 
          for (; from < end; from += interleave)
            for (i = 0; i < copy_width; i++)
-             *to++ = from[i];
+             {
+               if (&from[i] >= end)
+                 break;
+               *to++ = from[i];
+             }
 
          size = (size + interleave - 1 - copy_byte) / interleave * copy_width;
          osection->lma /= interleave;