summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-06-27 05:50:19 -0700
committerH.J. Lu <hjl.tools@gmail.com>2017-06-27 05:50:19 -0700
commitd728ffe4a200776f48d4af275b9052dabfaed749 (patch)
treeca1df24c6bd189250911fc4437e424f42bfaa4a0
parentafadd81b05d1d2a889369f4d9d0c746443ff2e2d (diff)
downloadbinutils-gdb-users/hl/pr21679.tar.gz
Don't call bfd_get_file_size in _bfd_generic_get_section_contentsusers/hl/pr21679
Since it is impossible to read beyond the end of normal files, we only need to check archive element size in _bfd_generic_get_section_contents * libbfd.c (_bfd_generic_get_section_contents): Don't call bfd_get_file_size. Check archive element size. (_bfd_generic_get_section_contents_in_window): Likewise.
-rw-r--r--bfd/libbfd.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index 0d9de2b30bd..82cffb865f8 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -788,8 +788,7 @@ _bfd_generic_get_section_contents (bfd *abfd,
file_ptr offset,
bfd_size_type count)
{
- bfd_size_type sz;
- ufile_ptr filesz;
+ bfd_size_type sz, end;
if (count == 0)
return TRUE;
@@ -812,10 +811,12 @@ _bfd_generic_get_section_contents (bfd *abfd,
sz = section->rawsize;
else
sz = section->size;
- filesz = bfd_get_file_size (abfd);
- if (offset + count < count
- || offset + count > sz
- || (ufile_ptr) section->filepos + offset + count > filesz)
+ end = offset + count;
+ if (end < count
+ || end > sz
+ || (abfd->my_archive != NULL
+ && !bfd_is_thin_archive (abfd->my_archive)
+ && (ufile_ptr) section->filepos + end > arelt_size (abfd)))
{
bfd_set_error (bfd_error_invalid_operation);
return FALSE;
@@ -837,8 +838,7 @@ _bfd_generic_get_section_contents_in_window
bfd_size_type count ATTRIBUTE_UNUSED)
{
#ifdef USE_MMAP
- bfd_size_type sz;
- ufile_ptr filesz;
+ bfd_size_type sz, end;
if (count == 0)
return TRUE;
@@ -871,9 +871,12 @@ _bfd_generic_get_section_contents_in_window
sz = section->rawsize;
else
sz = section->size;
- filesz = bfd_get_file_size (abfd);
- if (offset + count > sz
- || (ufile_ptr) section->filepos + offset + count > filesz
+ end = offset + count;
+ if (end < count
+ || end > sz
+ || (abfd->my_archive != NULL
+ && !bfd_is_thin_archive (abfd->my_archive)
+ && (ufile_ptr) section->filepos + end > arelt_size (abfd))
|| ! bfd_get_file_window (abfd, section->filepos + offset, count, w,
TRUE))
return FALSE;