2008-09-05 Cary Coutant <ccoutant@google.com>
authorCary Coutant <ccoutant@google.com>
Wed, 10 Sep 2008 17:56:02 +0000 (17:56 +0000)
committerCary Coutant <ccoutant@google.com>
Wed, 10 Sep 2008 17:56:02 +0000 (17:56 +0000)
* fileread.cc (File_read::make_view): Add check for attempt to map
beyond end of file.

gold/ChangeLog
gold/fileread.cc

index cac87e66e9a7f8a2c4aec2bd76326a9c7ea33d0b..1df7d7463919d1e9e662466af2dc752ebfd69320 100644 (file)
@@ -1,3 +1,8 @@
+2008-09-05  Cary Coutant  <ccoutant@google.com>
+
+       * fileread.cc (File_read::make_view): Add check for attempt to map
+       beyond end of file.
+
 2008-09-05  Cary Coutant  <ccoutant@google.com>
 
        * symtab.cc (Symbol_table::add_from_dynobj): Fix typos in
index 8c2f8f34cf3124baa9c1eb8c3ab076338b083de8..f56e33e39f16fdd90a452a38dc73b71fc1e290b4 100644 (file)
@@ -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));
This page took 0.031086 seconds and 4 git commands to generate.