summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2021-07-30 12:58:12 +0930
committerAlan Modra <amodra@gmail.com>2021-07-30 15:08:55 +0930
commit5cfe19e51ee06feb191b33a934bcf6cfaaace7b1 (patch)
tree1a42267c12b11f94e66e1cf5141b4ffd8fae25c5
parent472dd8b357e878b09ffa0703ad80b2915aaa4ec6 (diff)
reloc_upper_bound size calculations
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.
-rw-r--r--bfd/coffgen.c2
-rw-r--r--bfd/elf.c2
-rw-r--r--bfd/elf64-sparc.c2
-rw-r--r--bfd/mach-o.c2
-rw-r--r--bfd/vms-alpha.c2
5 files changed, 5 insertions, 5 deletions
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index ca93682846..77bda9e994 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -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 *
diff --git a/bfd/elf.c b/bfd/elf.c
index de5abafabf..d0898855de 100644
--- 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. */
diff --git a/bfd/elf64-sparc.c b/bfd/elf64-sparc.c
index 035ebdd45c..d43784a1b4 100644
--- a/bfd/elf64-sparc.c
+++ b/bfd/elf64-sparc.c
@@ -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
diff --git a/bfd/mach-o.c b/bfd/mach-o.c
index ff18ded23d..a26a68fa44 100644
--- a/bfd/mach-o.c
+++ b/bfd/mach-o.c
@@ -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
diff --git a/bfd/vms-alpha.c b/bfd/vms-alpha.c
index 41cc94440b..bd49b7af3c 100644
--- a/bfd/vms-alpha.c
+++ b/bfd/vms-alpha.c
@@ -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