aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-06-28 11:07:04 -0700
committerH.J. Lu <hjl.tools@gmail.com>2017-06-28 11:07:04 -0700
commit328ce951b2513a102711bb640496a2f1b5f8d3dd (patch)
tree410c0349ea93ed40c1d24e91f277c618d5c37986 /bfd
parent47fdcf63c04b5c220974affc8ff1d9ef8a041919 (diff)
downloadgdb-328ce951b2513a102711bb640496a2f1b5f8d3dd.zip
gdb-328ce951b2513a102711bb640496a2f1b5f8d3dd.tar.gz
gdb-328ce951b2513a102711bb640496a2f1b5f8d3dd.tar.bz2
Don't call bfd_get_file_size in _bfd_generic_get_section_contents
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.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog6
-rw-r--r--bfd/libbfd.c17
2 files changed, 16 insertions, 7 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 561ac1b..ad9eecb 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,11 @@
2017-06-28 H.J. Lu <hongjiu.lu@intel.com>
+ * 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.
+
+2017-06-28 H.J. Lu <hongjiu.lu@intel.com>
+
* bfd-in2.h: Regenerated.
* bfdio.c (bfd_get_size): Change return type to ufile_ptr.
(bfd_get_file_size): Likewise.
diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index 0d9de2b..2a49b61 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -789,7 +789,6 @@ _bfd_generic_get_section_contents (bfd *abfd,
bfd_size_type count)
{
bfd_size_type sz;
- ufile_ptr filesz;
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)
+ || (abfd->my_archive != NULL
+ && !bfd_is_thin_archive (abfd->my_archive)
+ && ((ufile_ptr) section->filepos + offset + count
+ > arelt_size (abfd))))
{
bfd_set_error (bfd_error_invalid_operation);
return FALSE;
@@ -838,7 +839,6 @@ _bfd_generic_get_section_contents_in_window
{
#ifdef USE_MMAP
bfd_size_type sz;
- ufile_ptr filesz;
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
+ if (offset + count < count
+ || offset + count > sz
+ || (abfd->my_archive != NULL
+ && !bfd_is_thin_archive (abfd->my_archive)
+ && ((ufile_ptr) section->filepos + offset + count
+ > arelt_size (abfd)))
|| ! bfd_get_file_window (abfd, section->filepos + offset, count, w,
TRUE))
return FALSE;