This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
RFA: Have gold's File_read::do_read() function check the start parameter (PR 23765)
- From: Nick Clifton <nickc at redhat dot com>
- To: ccoutant at gmail dot com
- Cc: binutils at sourceware dot org
- Date: Tue, 06 Aug 2019 14:16:17 +0100
- Subject: 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)
{