aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf64-sparc.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfd/elf64-sparc.c')
-rw-r--r--bfd/elf64-sparc.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/bfd/elf64-sparc.c b/bfd/elf64-sparc.c
index e9f03cf..fb4483d 100644
--- a/bfd/elf64-sparc.c
+++ b/bfd/elf64-sparc.c
@@ -37,14 +37,25 @@
static long
elf64_sparc_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
{
-#if SIZEOF_LONG == SIZEOF_INT
- if (sec->reloc_count >= LONG_MAX / 2 / sizeof (arelent *))
+ size_t count, raw;
+
+ count = sec->reloc_count;
+ if (count >= LONG_MAX / 2 / sizeof (arelent *)
+ || _bfd_mul_overflow (count, sizeof (Elf64_External_Rela), &raw))
{
bfd_set_error (bfd_error_file_too_big);
return -1;
}
-#endif
- return (sec->reloc_count * 2L + 1) * sizeof (arelent *);
+ if (!bfd_write_p (abfd))
+ {
+ ufile_ptr filesize = bfd_get_file_size (abfd);
+ if (filesize != 0 && raw > filesize)
+ {
+ bfd_set_error (bfd_error_file_truncated);
+ return -1;
+ }
+ }
+ return (count * 2 + 1) * sizeof (arelent *);
}
static long