This is the mail archive of the 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]

[PATCH] Fix failure of 32-bit linker on large files

Hi all,

I've found that while linking pretty large files the bfd_seek() function may
be called with incorrect negative value of argument "position". The
"position" value is negative due to overflow in local variable of type long.
That happens in _bfd_elf_set_section_contents():

  bfd_signed_vma pos;
  pos = hdr->sh_offset + offset;
  if (bfd_seek (abfd, pos, SEEK_SET) != 0

Both addends are of long long type, the result is used as long long as well.
Using the long type for intermediate result seems to be a bug. That leads
32-bit linker to fail for large (~2Gb) files. The Bugzilla entry for this:  
Proposed patch is attached.


	PR ld/16803
	Fixed integer overflow.

	* elf.c (_bfd_elf_set_section_contents): Fixed type of local

diff --git a/bfd/elf.c b/bfd/elf.c
index 3ded683..2fee9ac 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -7800,7 +7800,7 @@ _bfd_elf_set_section_contents (bfd *abfd,
 			       bfd_size_type count)
   Elf_Internal_Shdr *hdr;
-  bfd_signed_vma pos;
+  file_ptr pos;
   if (! abfd->output_has_begun
       && ! _bfd_elf_compute_section_file_positions (abfd, NULL))

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