aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2022-06-27 13:07:40 +0100
committerNick Clifton <nickc@redhat.com>2022-06-27 13:07:40 +0100
commit2a4fc266dbf77ed7ab83da16468e9ba627b8bc2d (patch)
treeb2258d224f8f9bfe458a2fa8d20c15a332dfdaf3
parent8c9ae6df3c244a7a738085ab461cb098df1d46f6 (diff)
downloadgdb-2a4fc266dbf77ed7ab83da16468e9ba627b8bc2d.zip
gdb-2a4fc266dbf77ed7ab83da16468e9ba627b8bc2d.tar.gz
gdb-2a4fc266dbf77ed7ab83da16468e9ba627b8bc2d.tar.bz2
Have gold's File_read::do_read() function check the start parameter
PR 23765 * fileread.cc (File_read::do_read): Check start parameter before computing number of bytes to read.
-rw-r--r--gold/ChangeLog6
-rw-r--r--gold/fileread.cc6
2 files changed, 12 insertions, 0 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index 5103dab..8557dc6 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -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
diff --git a/gold/fileread.cc b/gold/fileread.cc
index 2b653f7..af2df21 100644
--- a/gold/fileread.cc
+++ b/gold/fileread.cc
@@ -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)
{