aboutsummaryrefslogtreecommitdiff
path: root/bfd/coffgen.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfd/coffgen.c')
-rw-r--r--bfd/coffgen.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index 3e0fbc6..aab41c3 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -1976,19 +1976,25 @@ coff_get_normalized_symtab (bfd *abfd)
long
coff_get_reloc_upper_bound (bfd *abfd, sec_ptr asect)
{
- if (bfd_get_format (abfd) != bfd_object)
+ size_t count, raw;
+
+ count = asect->reloc_count;
+ if (count >= LONG_MAX / sizeof (arelent *)
+ || _bfd_mul_overflow (count, bfd_coff_relsz (abfd), &raw))
{
- bfd_set_error (bfd_error_invalid_operation);
+ bfd_set_error (bfd_error_file_too_big);
return -1;
}
-#if SIZEOF_LONG == SIZEOF_INT
- if (asect->reloc_count >= LONG_MAX / sizeof (arelent *))
+ if (!bfd_write_p (abfd))
{
- bfd_set_error (bfd_error_file_too_big);
- return -1;
+ ufile_ptr filesize = bfd_get_file_size (abfd);
+ if (filesize != 0 && raw > filesize)
+ {
+ bfd_set_error (bfd_error_file_truncated);
+ return -1;
+ }
}
-#endif
- return (asect->reloc_count + 1L) * sizeof (arelent *);
+ return (count + 1) * sizeof (arelent *);
}
asymbol *