1From 2a4fc266dbf77ed7ab83da16468e9ba627b8bc2d Mon Sep 17 00:00:00 2001 2From: Nick Clifton <nickc@redhat.com> 3Date: Mon, 27 Jun 2022 13:07:40 +0100 4Subject: [PATCH] Have gold's File_read::do_read() function check the start 5 parameter 6 7 PR 23765 8 * fileread.cc (File_read::do_read): Check start parameter before 9 computing number of bytes to read. 10 11Upstream-Status: Backport [https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2a4fc266dbf77ed7ab83da16468e9ba627b8bc2d] 12 13Signed-off-by: Pgowda <pgowda.cve@gmail.com> 14--- 15 gold/ChangeLog | 6 ++++++ 16 gold/fileread.cc | 6 ++++++ 17 2 files changed, 12 insertions(+) 18 19diff --git a/gold/ChangeLog b/gold/ChangeLog 20index 5103dab7b67..8557dc6db7f 100644 21--- a/gold/ChangeLog 22+++ b/gold/ChangeLog 23@@ -1,3 +1,9 @@ 24+2022-06-27 Nick Clifton <nickc@redhat.com> 25+ 26+ PR 23765 27+ * fileread.cc (File_read::do_read): Check start parameter before 28+ computing number of bytes to read. 29+ 30 2022-02-17 Nick Clifton <nickc@redhat.com> 31 32 * po/sr.po: Updated Serbian translation. 33diff --git a/gold/fileread.cc b/gold/fileread.cc 34index 2b653f78c2e..af2df215468 100644 35--- a/gold/fileread.cc 36+++ b/gold/fileread.cc 37@@ -385,6 +385,12 @@ File_read::do_read(off_t start, section_ 38 ssize_t bytes; 39 if (this->whole_file_view_ != NULL) 40 { 41+ // See PR 23765 for an example of a testcase that triggers this error. 42+ if (((ssize_t) start) < 0) 43+ gold_fatal(_("%s: read failed, starting offset (%#llx) less than zero"), 44+ this->filename().c_str(), 45+ static_cast<long long>(start)); 46+ 47 bytes = this->size_ - start; 48 if (static_cast<section_size_type>(bytes) >= size) 49 { 50