Have gold's File_read::do_read() function check the start parameter
authorNick Clifton <nickc@redhat.com>
Mon, 27 Jun 2022 12:07:40 +0000 (13:07 +0100)
committerNick Clifton <nickc@redhat.com>
Mon, 27 Jun 2022 12:07:40 +0000 (13:07 +0100)
PR 23765
* fileread.cc (File_read::do_read): Check start parameter before
computing number of bytes to read.

gold/ChangeLog
gold/fileread.cc

index 5103dab7b67083792da263bcd58f44d325bfdc83..8557dc6db7f5f8756f48368f26ae1e54f2941341 100644 (file)
@@ -1,3 +1,9 @@
+2022-06-27  Nick Clifton  <nickc@redhat.com>
+
+       PR 23765
+       * fileread.cc (File_read::do_read): Check start parameter before
+       computing number of bytes to read.
+
 2022-05-18  Nick Clifton  <nickc@redhat.com>
 
        * int_encoding.cc (get_length_as_unsigned_LEB_128): Remove
index 2b653f78c2e14e6cf5af2ae1c5366b797e182958..af2df21546861e2b6a8ce8dd4c05a5c4136f38a1 100644 (file)
@@ -385,6 +385,12 @@ File_read::do_read(off_t start, section_size_type size, void* p)
   ssize_t bytes;
   if (this->whole_file_view_ != NULL)
     {
+      // See PR 23765 for an example of a testcase that triggers this error.
+      if (((ssize_t) start) < 0)
+       gold_fatal(_("%s: read failed, starting offset (%#llx) less than zero"),
+                  this->filename().c_str(),
+                  static_cast<long long>(start));
+       
       bytes = this->size_ - start;
       if (static_cast<section_size_type>(bytes) >= size)
        {