gdb/dwarf: fix bound check in read_rnglist_index
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 2 Feb 2021 15:40:50 +0000 (10:40 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Tue, 2 Feb 2021 15:40:50 +0000 (10:40 -0500)
I think this check in read_rnglist_index is wrong:

      /* Validate that reading won't go beyond the end of the section.  */
      if (start_offset + cu->header.offset_size > rnglist_base + section->size)
        error (_("Reading DW_FORM_rnglistx index beyond end of"
                 ".debug_rnglists section [in module %s]"),
               objfile_name (objfile));

The addition `rnglist_base + section->size` doesn't make sense.
rnglist_base is an offset into `section`, so it doesn't make sense to
add it to `section`'s size.  `start_offset` also is an offset into
`section`, so we should just compare it to just `section->size`.

gdb/ChangeLog:

* dwarf2/read.c (read_rnglist_index): Fix bound check.

Change-Id: If0ff7c73f4f80f79aac447518f4e8f131f2db8f2

gdb/ChangeLog
gdb/dwarf2/read.c

index dcbfc77761d5b5bd568cab39ea701bc86b8b59bb..c71492d7a3301ad02979f5f11fb93e6b85f190a4 100644 (file)
@@ -1,3 +1,7 @@
+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>
 
        * dwarf2/read.c (read_loclist_index): Change complaints into
index a9f7ce3a3122e4cc209153a6615df577d0c43fa9..9a71329c990d00857ddedb7b09a5f2555a510844 100644 (file)
@@ -20257,6 +20257,8 @@ read_rnglist_index (struct dwarf2_cu *cu, ULONGEST rnglist_index,
      : RNGLIST_HEADER_SIZE64);
   ULONGEST rnglist_base =
       (cu->dwo_unit != nullptr) ? rnglist_header_size : cu->ranges_base;
+
+  /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX.  */
   ULONGEST start_offset =
     rnglist_base + rnglist_index * cu->header.offset_size;
 
@@ -20285,7 +20287,7 @@ read_rnglist_index (struct dwarf2_cu *cu, ULONGEST rnglist_index,
           objfile_name (objfile));
 
   /* Validate that reading won't go beyond the end of the section.  */
-  if (start_offset + cu->header.offset_size > rnglist_base + section->size)
+  if (start_offset + cu->header.offset_size > section->size)
     error (_("Reading DW_FORM_rnglistx index beyond end of"
             ".debug_rnglists section [in module %s]"),
           objfile_name (objfile));
This page took 0.04402 seconds and 4 git commands to generate.