aboutsummaryrefslogtreecommitdiff
path: root/gold
diff options
context:
space:
mode:
authorCary Coutant <ccoutant@google.com>2011-10-17 23:36:43 +0000
committerCary Coutant <ccoutant@google.com>2011-10-17 23:36:43 +0000
commitcdd7e2444cac5765557ebecd53ae91b7d2bcb0f1 (patch)
tree756a58f240f5fa886583d10181f8066bb7153047 /gold
parent42dd20afd3c33861a4d0b327a492413fc54e1d71 (diff)
downloadgdb-cdd7e2444cac5765557ebecd53ae91b7d2bcb0f1.zip
gdb-cdd7e2444cac5765557ebecd53ae91b7d2bcb0f1.tar.gz
gdb-cdd7e2444cac5765557ebecd53ae91b7d2bcb0f1.tar.bz2
PR gold/13288
* gold/fileread.cc (File_read::find_view): Add assert. (File_read::make_view): Move bounds check (replace with assert)... (File_read::find_or_make_view): ... to here.
Diffstat (limited to 'gold')
-rw-r--r--gold/ChangeLog7
-rw-r--r--gold/fileread.cc27
2 files changed, 24 insertions, 10 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index e6e8a9b..e89bf81 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,3 +1,10 @@
+2011-10-17 Cary Coutant <ccoutant@google.com>
+
+ PR gold/13288
+ * gold/fileread.cc (File_read::find_view): Add assert.
+ (File_read::make_view): Move bounds check (replace with assert)...
+ (File_read::find_or_make_view): ... to here.
+
2011-10-12 Cary Coutant <ccoutant@google.com>
* gold/output.cc (Output_file::open_base_file): Handle case where
diff --git a/gold/fileread.cc b/gold/fileread.cc
index 80ddfbc..c5dc320 100644
--- a/gold/fileread.cc
+++ b/gold/fileread.cc
@@ -329,6 +329,10 @@ inline File_read::View*
File_read::find_view(off_t start, section_size_type size,
unsigned int byteshift, File_read::View** vshifted) const
{
+ gold_assert(start <= this->size_
+ && (static_cast<unsigned long long>(size)
+ <= static_cast<unsigned long long>(this->size_ - start)));
+
if (vshifted != NULL)
*vshifted = NULL;
@@ -456,16 +460,9 @@ File_read::make_view(off_t start, section_size_type size,
unsigned int byteshift, bool cache)
{
gold_assert(size > 0);
-
- // Check that start and end of the view are within the file.
- if (start > this->size_
- || (static_cast<unsigned long long>(size)
- > static_cast<unsigned long long>(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));
+ gold_assert(start <= this->size_
+ && (static_cast<unsigned long long>(size)
+ <= static_cast<unsigned long long>(this->size_ - start)));
off_t poff = File_read::page_offset(start);
@@ -523,6 +520,16 @@ File_read::View*
File_read::find_or_make_view(off_t offset, off_t start,
section_size_type size, bool aligned, bool cache)
{
+ // Check that start and end of the view are within the file.
+ if (start > this->size_
+ || (static_cast<unsigned long long>(size)
+ > static_cast<unsigned long long>(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));
+
unsigned int byteshift;
if (offset == 0)
byteshift = 0;