This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFA: Have gold's File_read::do_read() function check the start parameter (PR 23765)


Hi Cary,

  Attached is a small proposed patch for PR 23765.  The C++ coding may
  not be all that good as I am not a C++ expert, but it does build and
  test without introducing any new regressions.

  OK to apply ?

Cheers
  Nick

gold/ChangeLog
2019-08-06  Nick Clifton  <nickc@redhat.com>

	PR 23765
	* fileread.cc (File_read::do_read): Check start parameter before
	computing number of bytes to read.

diff --git a/gold/fileread.cc b/gold/fileread.cc
index c4ab6b7d04..7ca00b3702 100644
--- a/gold/fileread.cc
+++ b/gold/fileread.cc
@@ -381,6 +381,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)
 	{


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]