PR25648, objcopy SIGSEGV in ihex_write_record

Message ID 20200310003637.GR5384@bubble.grove.modra.org
State New
Headers show
Series
  • PR25648, objcopy SIGSEGV in ihex_write_record
Related show

Commit Message

Alan Modra March 10, 2020, 12:36 a.m.
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.


-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/bfd/ihex.c b/bfd/ihex.c
index 68671cc623..f084c5aad9 100644
--- a/bfd/ihex.c
+++ b/bfd/ihex.c
@@ -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;