aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2021-02-02 10:40:51 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2021-02-02 10:40:51 -0500
commit05787bad362024d1328c0d6f7c51244a7d6c1e75 (patch)
treeb87949bde02828ff51b02657675027f4faabaacc
parent5e4d9bbc4b4e57eacb614c38f30dac9af08cace8 (diff)
downloadgdb-05787bad362024d1328c0d6f7c51244a7d6c1e75.zip
gdb-05787bad362024d1328c0d6f7c51244a7d6c1e75.tar.gz
gdb-05787bad362024d1328c0d6f7c51244a7d6c1e75.tar.bz2
gdb/dwarf: add missing bound check to read_loclist_index
read_rnglist_index has a bound check to make sure that we don't go past the end of the section while reading the offset, but read_loclist_index doesn't. Add it to read_loclist_index. gdb/ChangeLog: * dwarf2/read.c (read_loclist_index): Add bound check for the end of the offset. Change-Id: Ic4b55c88860fdc3e007740949c78ec84cdb4da60
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/dwarf2/read.c17
2 files changed, 18 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c71492d..8dd3147 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2021-02-02 Simon Marchi <simon.marchi@efficios.com>
+ * dwarf2/read.c (read_loclist_index): Add bound check for the end
+ of the offset.
+
+2021-02-02 Simon Marchi <simon.marchi@efficios.com>
+
* dwarf2/read.c (read_rnglist_index): Fix bound check.
2021-02-02 Simon Marchi <simon.marchi@efficios.com>
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 9a71329..8d1edc2 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -20214,6 +20214,11 @@ read_loclist_index (struct dwarf2_cu *cu, ULONGEST loclist_index)
struct objfile *objfile = per_objfile->objfile;
bfd *abfd = objfile->obfd;
ULONGEST loclist_base = lookup_loclist_base (cu);
+
+ /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
+ ULONGEST start_offset =
+ loclist_base + loclist_index * cu->header.offset_size;
+
struct dwarf2_section_info *section = cu_debug_loc_section (cu);
section->read (objfile);
@@ -20228,14 +20233,18 @@ read_loclist_index (struct dwarf2_cu *cu, ULONGEST loclist_index)
".debug_loclists offset array [in module %s]"),
objfile_name (objfile));
- if (loclist_base + loclist_index * cu->header.offset_size
- >= section->size)
+ if (start_offset >= section->size)
error (_("DW_FORM_loclistx pointing outside of "
".debug_loclists section [in module %s]"),
objfile_name (objfile));
- const gdb_byte *info_ptr
- = section->buffer + loclist_base + loclist_index * cu->header.offset_size;
+ /* Validate that reading won't go beyond the end of the section. */
+ if (start_offset + cu->header.offset_size > section->size)
+ error (_("Reading DW_FORM_loclistx index beyond end of"
+ ".debug_loclists section [in module %s]"),
+ objfile_name (objfile));
+
+ const gdb_byte *info_ptr = section->buffer + start_offset;
if (cu->header.offset_size == 4)
return bfd_get_32 (abfd, info_ptr) + loclist_base;