[binutils-gdb] Use ufile_ptr for file position

Alan Modra via Binutils-cvs <[email protected]> Mon, 27 Jul 2026 06:24:22 +0000 (GMT)
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D8bff282ca5ca=
40d6acdf492e1db347d082cd1b01

commit 8bff282ca5ca40d6acdf492e1db347d082cd1b01
Author: Alan Modra <[email protected]>
Date:   Mon Jul 27 14:58:50 2026 +0930

    Use ufile_ptr for file position
   =20
    This is in response to a fuzzed objcopy test that overflows file_ptr
    addition.  It makes sense to use an unsigned value for current file
    offset, and allows a couple of casts to be removed.
   =20
            * elf.c (assign_file_positions_for_load_sections): Make off uns=
igned.
            (assign_file_positions_except_relocs): Likewise.
            (_bfd_elf_assign_file_positions_for_non_load): Likewise.

Diff:
---
 bfd/elf.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/bfd/elf.c b/bfd/elf.c
index 6c31dabae63..ea127919b9f 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -5885,7 +5885,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
   struct elf_segment_map *phdr_load_seg;
   Elf_Internal_Phdr *phdrs;
   Elf_Internal_Phdr *p;
-  file_ptr off;  /* Octets.  */
+  ufile_ptr off;  /* Octets.  */
   bfd_size_type maxpagesize;
   unsigned int alloc, actual;
   unsigned int i, j;
@@ -6175,9 +6175,9 @@ assign_file_positions_for_load_sections (bfd *abfd,
 	    {
 	      if (m->count > 0)
 		{
-		  if (p->p_vaddr < (bfd_vma) off
+		  if (p->p_vaddr < off
 		      || (!m->p_paddr_valid
-			  && p->p_paddr < (bfd_vma) off))
+			  && p->p_paddr < off))
 		    {
 		      _bfd_error_handler
 			(_("%pB: not enough room for program headers,"
@@ -6595,7 +6595,7 @@ assign_file_positions_for_non_load_sections (bfd *abf=
d,
   Elf_Internal_Phdr *phdrs;
   Elf_Internal_Phdr *p;
   struct elf_segment_map *m;
-  file_ptr off;
+  ufile_ptr off;
   unsigned int opb =3D bfd_octets_per_byte (abfd, NULL);
   bfd_vma maxpagesize;
=20
@@ -6864,7 +6864,7 @@ assign_file_positions_except_relocs (bfd *abfd,
       unsigned int num_sec =3D elf_numsections (abfd);
       Elf_Internal_Shdr **hdrpp;
       unsigned int i;
-      file_ptr off;
+      ufile_ptr off;
=20
       /* Start after the ELF header.  */
       off =3D i_ehdrp->e_ehsize;
@@ -7110,7 +7110,7 @@ _bfd_elf_modify_headers (bfd *obfd, struct bfd_link_i=
nfo *link_info)
 static bool
 _bfd_elf_assign_file_positions_for_non_load (bfd *abfd)
 {
-  file_ptr off;
+  ufile_ptr off;
   Elf_Internal_Shdr **shdrpp, **end_shdrpp;
   Elf_Internal_Shdr *shdrp;
   Elf_Internal_Ehdr *i_ehdrp;