[Gold] Don't get a section name if the offset is bad
Miguel Saldivar
saldivarcher@gmail.com
Fri Sep 3 20:53:39 GMT 2021
This is a fix for: https://sourceware.org/bugzilla/show_bug.cgi?id=26765
When getting an offset value that doesn't exist in the section name string
table, we shouldn't try to get the section name, rather just return from
the function.
Thanks,
Miguel Saldivar
diff --git a/elfcpp/ChangeLog b/elfcpp/ChangeLog
index 0d149351e8a..490b4fd025d 100644
--- a/elfcpp/ChangeLog
+++ b/elfcpp/ChangeLog
@@ -1,3 +1,8 @@
+2021-09-03 Miguel Saldivar <saldivarcher@gmail.com>
+
+ * elfcpp_file.h (Elf_file::section_name): Do not get section name,
if the
+ offset is bad.
+
2021-07-03 Nick Clifton <nickc@redhat.com>
* 2.37 release branch created.
diff --git a/elfcpp/elfcpp_file.h b/elfcpp/elfcpp_file.h
index 8d4aac8bbae..56811bf9740 100644
--- a/elfcpp/elfcpp_file.h
+++ b/elfcpp/elfcpp_file.h
@@ -532,9 +532,12 @@ Elf_file<size, big_endian,
File>::section_name(unsigned int shndx) const
shstr_size = shstr_shdr.get_sh_size();
}
- if (sh_name >= shstr_size)
+ if (sh_name >= shstr_size) {
file->error(_("bad section name offset for section %u: %u"),
shndx, sh_name);
+ // Don't try to get the section name if the offset is bad.
+ return std::string();
+ }
typename File::View v(file->view(shstr_off, shstr_size));
More information about the Binutils
mailing list