aboutsummaryrefslogtreecommitdiff
path: root/gold/fileread.cc
diff options
context:
space:
mode:
authorCary Coutant <ccoutant@google.com>2008-09-10 17:56:02 +0000
committerCary Coutant <ccoutant@google.com>2008-09-10 17:56:02 +0000
commita9caad024e20635ecebb7be5330747fe23a7292b (patch)
tree6cfb7c02315baa1e27e8d96ce2e6acd5333f908e /gold/fileread.cc
parentebcf6f00fcd8bd37721863ca65290c9b28a13d60 (diff)
downloadfsf-binutils-gdb-a9caad024e20635ecebb7be5330747fe23a7292b.zip
fsf-binutils-gdb-a9caad024e20635ecebb7be5330747fe23a7292b.tar.gz
fsf-binutils-gdb-a9caad024e20635ecebb7be5330747fe23a7292b.tar.bz2
2008-09-05 Cary Coutant <ccoutant@google.com>
* fileread.cc (File_read::make_view): Add check for attempt to map beyond end of file.
Diffstat (limited to 'gold/fileread.cc')
-rw-r--r--gold/fileread.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/gold/fileread.cc b/gold/fileread.cc
index 8c2f8f3..f56e33e 100644
--- a/gold/fileread.cc
+++ b/gold/fileread.cc
@@ -355,6 +355,14 @@ File_read::make_view(off_t start, section_size_type size,
{
gold_assert(size > 0);
+ // Check that start and end of the view are within the file.
+ if (start > this->size_ || size > this->size_ - start)
+ gold_fatal(_("%s: attempt to map %lld bytes at offset %lld exceeds "
+ "size of file; the file may be corrupt"),
+ this->filename().c_str(),
+ static_cast<long long>(size),
+ static_cast<long long>(start));
+
off_t poff = File_read::page_offset(start);
section_size_type psize = File_read::pages(size + (start - poff));