This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [committed, PATCH] Properly convert objects between different ELF classes


On 10/07/15 22:43, H.J. Lu wrote:
-  size = bfd_get_section_size (isection);
+  /* The output SHF_COMPRESSED section size is different from input if
+     ELF classes of input and output aren't the same.  We must use the
+     output section size here, which has been updated in setup_section
+     via bfd_convert_section_size.  */
+  size = bfd_get_section_size (osection);

This change has broken objcopy when padding has been added to the output section size. In my case, the output is binary format.

The bug causes a buffer read overrun which results in intermittent failures. It also looks like it will break byte reversal and interleaving.

The attached patch fixes the problem.

OK to commit?

Andrew
2015-09-24  Andrew Stubbs  <ams@codesourcery.com>

	binutils/
	* objcopy.c (copy_section): Use input section size for the copy.

Index: binutils/objcopy.c
===================================================================
--- binutils/objcopy.c	(revision 455071)
+++ binutils/objcopy.c	(working copy)
@@ -3126,22 +3126,17 @@
   bfd *obfd = (bfd *) obfdarg;
   struct section_list *p;
   sec_ptr osection;
-  bfd_size_type size;
 
   if (skip_section (ibfd, isection))
     return;
 
   osection = isection->output_section;
-  /* The output SHF_COMPRESSED section size is different from input if
-     ELF classes of input and output aren't the same.  We must use the
-     output section size here, which has been updated in setup_section
-     via bfd_convert_section_size.  */
-  size = bfd_get_section_size (osection);
 
   if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS
       && bfd_get_section_flags (obfd, osection) & SEC_HAS_CONTENTS)
     {
       bfd_byte *memhunk = NULL;
+      bfd_size_type size;
 
       if (!bfd_get_full_section_contents (ibfd, isection, &memhunk)
 	  || !bfd_convert_section_contents (ibfd, isection, obfd,
@@ -3152,6 +3147,9 @@
 	  return;
 	}
 
+      /* Use the input size *after* conversion.  */
+      size = bfd_get_section_size (isection);
+
       if (reverse_bytes)
 	{
 	  /* We don't handle leftover bytes (too many possible behaviors,
@@ -3210,6 +3208,7 @@
 				   FALSE, SECTION_CONTEXT_SET_FLAGS)) != NULL
 	   && (p->flags & SEC_HAS_CONTENTS) != 0)
     {
+      bfd_size_type size = bfd_get_section_size (osection);
       void *memhunk = xmalloc (size);
 
       /* We don't permit the user to turn off the SEC_HAS_CONTENTS

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]