]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Don't call bfd_get_file_size in _bfd_generic_get_section_contents
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 28 Jun 2017 18:07:04 +0000 (11:07 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 28 Jun 2017 18:07:04 +0000 (11:07 -0700)
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.

bfd/ChangeLog
bfd/libbfd.c

index 561ac1b352130aed30c9184ce6c3a862dd154af2..ad9eecb4b765ec6a266a3adce4f617ce1cf4d2ee 100644 (file)
@@ -1,3 +1,9 @@
+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.
index 0d9de2b30bd5da7c3e057266fdf48a3d25bdc3e6..2a49b61d2b441306c55f8683c7a380553263432a 100644 (file)
@@ -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;