aboutsummaryrefslogtreecommitdiff
path: root/bfd/mach-o.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfd/mach-o.c')
-rw-r--r--bfd/mach-o.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/bfd/mach-o.c b/bfd/mach-o.c
index 5279343..664ff44 100644
--- a/bfd/mach-o.c
+++ b/bfd/mach-o.c
@@ -1407,17 +1407,27 @@ bfd_mach_o_write_dyld_info (bfd *abfd, bfd_mach_o_load_command *command)
}
long
-bfd_mach_o_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
- asection *asect)
+bfd_mach_o_get_reloc_upper_bound (bfd *abfd, asection *asect)
{
-#if SIZEOF_LONG == SIZEOF_INT
- if (asect->reloc_count >= LONG_MAX / sizeof (arelent *))
+ size_t count, raw;
+
+ count = asect->reloc_count;
+ if (count >= LONG_MAX / sizeof (arelent *)
+ || _bfd_mul_overflow (count, BFD_MACH_O_RELENT_SIZE, &raw))
{
bfd_set_error (bfd_error_file_too_big);
return -1;
}
-#endif
- return (asect->reloc_count + 1L) * 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 + 1) * sizeof (arelent *);
}
/* In addition to the need to byte-swap the symbol number, the bit positions