PR25648, objcopy SIGSEGV in ihex_write_record
authorAlan Modra <amodra@gmail.com>
Tue, 10 Mar 2020 00:16:17 +0000 (10:46 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 10 Mar 2020 00:35:07 +0000 (11:05 +1030)
ihex_set_section_contents sorts records stored on the tdata.ihex_data
list by address, but ihex_write_object_contents went too far in
assuming they were not overlapping.  This patch fixes the problem by
not assuming anything about addresses in ihex_write_object_contents.

PR 25648
* ihex.c (ihex_write_object_contents): Don't assume ordering of
addresses here.  Remove dead code.

bfd/ChangeLog
bfd/ihex.c

index 371e505392d561e3d69530b3e534d901e59206d7..67858c7538b11e5f6f073fb0686827ab6620eecb 100644 (file)
@@ -1,3 +1,9 @@
+2020-03-10  Alan Modra  <amodra@gmail.com>
+
+       PR 25648
+       * ihex.c (ihex_write_object_contents): Don't assume ordering of
+       addresses here.
+
 2020-03-09  Alan Modra  <amodra@gmail.com>
 
        * wasm-module.c (wasm_scan): Sanity check file name length
index 68671cc6239357ec76088eccf87cb11f6e5227ff..ca36043fe2daf48d8e7c68249f1df2311cdb9f37 100644 (file)
@@ -811,16 +811,15 @@ ihex_write_object_contents (bfd *abfd)
          if (count > CHUNK)
            now = CHUNK;
 
-         if (where > segbase + extbase + 0xffff)
+         if (where < extbase
+             || where - extbase < segbase
+             || where - extbase - segbase > 0xffff)
            {
              bfd_byte addr[2];
 
              /* We need a new base address.  */
-             if (where <= 0xfffff)
+             if (extbase == 0 && where <= 0xfffff)
                {
-                 /* The addresses should be sorted.  */
-                 BFD_ASSERT (extbase == 0);
-
                  segbase = where & 0xf0000;
                  addr[0] = (bfd_byte)(segbase >> 12) & 0xff;
                  addr[1] = (bfd_byte)(segbase >> 4) & 0xff;