]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
reloc_upper_bound size calculations
authorAlan Modra <amodra@gmail.com>
Fri, 30 Jul 2021 03:28:12 +0000 (12:58 +0930)
committerAlan Modra <amodra@gmail.com>
Fri, 30 Jul 2021 05:38:55 +0000 (15:08 +0930)
Section reloc_count is an unsigned int.  Adding one for a NULL
terminator to an array of arelent pointers can wrap the count to
zero.  Avoid that by doing the addition as longs.

* coffgen.c (coff_get_reloc_upper_bound): Don't overflow unsigned
int expression.
* elf.c (_bfd_elf_get_reloc_upper_bound): Likewise.
* elf64-sparc.c (elf64_sparc_get_reloc_upper_bound): Likewise.
* mach-o.c (bfd_mach_o_get_reloc_upper_bound): Likewise.
* vms-alpha.c (alpha_vms_get_reloc_upper_bound): Likewise.

bfd/coffgen.c
bfd/elf.c
bfd/elf64-sparc.c
bfd/mach-o.c
bfd/vms-alpha.c

index ca93682846848fb34602938fe4fc19ad668699dd..77bda9e99471d8f64f2843d33cf1e51b25df9a29 100644 (file)
@@ -1996,7 +1996,7 @@ coff_get_reloc_upper_bound (bfd *abfd, sec_ptr asect)
       return -1;
     }
 #endif
-  return (asect->reloc_count + 1) * sizeof (arelent *);
+  return (asect->reloc_count + 1L) * sizeof (arelent *);
 }
 
 asymbol *
index de5abafabf0b888c31a6f1eeeda529c921de467e..d0898855de8a2b8d8cf7f3f7aa230dcc795bc738 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -8559,7 +8559,7 @@ _bfd_elf_get_reloc_upper_bound (bfd *abfd, sec_ptr asect)
       return -1;
     }
 #endif
-  return (asect->reloc_count + 1) * sizeof (arelent *);
+  return (asect->reloc_count + 1L) * sizeof (arelent *);
 }
 
 /* Canonicalize the relocs.  */
index 035ebdd45ce6139820d95c3e4dbbc352eaf4c912..d43784a1b44e6997c19bf4437228a720b4ad265f 100644 (file)
@@ -44,7 +44,7 @@ elf64_sparc_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
       return -1;
     }
 #endif
-  return (sec->reloc_count * 2 + 1) * sizeof (arelent *);
+  return (sec->reloc_count * 2L + 1) * sizeof (arelent *);
 }
 
 static long
index ff18ded23d50ccfba67ce1a3f1984c9411e0d111..a26a68fa440e909c0c71635906d2e138c7dd9126 100644 (file)
@@ -1427,7 +1427,7 @@ bfd_mach_o_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
       return -1;
     }
 #endif
- return (asect->reloc_count + 1) * sizeof (arelent *);
+ return (asect->reloc_count + 1L) * sizeof (arelent *);
 }
 
 /* In addition to the need to byte-swap the symbol number, the bit positions
index 41cc94440b348be818b5c59f47b8e82eb50319bc..bd49b7af3c7d6149c9e99720dae1c2fd865fd7ef 100644 (file)
@@ -5443,7 +5443,7 @@ alpha_vms_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *section)
 {
   alpha_vms_slurp_relocs (abfd);
 
-  return (section->reloc_count + 1) * sizeof (arelent *);
+  return (section->reloc_count + 1L) * sizeof (arelent *);
 }
 
 /* Convert relocations from VMS (external) form into BFD internal