libbacktrace: correct buffer overflow tests
authorIan Lance Taylor <iant@golang.org>
Wed, 2 Dec 2020 19:06:40 +0000 (11:06 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 2 Dec 2020 19:07:59 +0000 (11:07 -0800)
* dwarf.c (resolve_string): Use > rather than >= to check whether
string index extends past buffer.
(resolve_addr_index): Similarly for address index.

libbacktrace/dwarf.c

index 582f34bc816b27b305e805507d1967182d33b127..0c913c95983b2d9f90a4276934817bc3765d9c66 100644 (file)
@@ -1053,7 +1053,7 @@ resolve_string (const struct dwarf_sections *dwarf_sections, int is_dwarf64,
 
        offset = val->u.uint * (is_dwarf64 ? 8 : 4) + str_offsets_base;
        if (offset + (is_dwarf64 ? 8 : 4)
-           >= dwarf_sections->size[DEBUG_STR_OFFSETS])
+           > dwarf_sections->size[DEBUG_STR_OFFSETS])
          {
            error_callback (data, "DW_FORM_strx value out of range", 0);
            return 0;
@@ -1097,7 +1097,7 @@ resolve_addr_index (const struct dwarf_sections *dwarf_sections,
   struct dwarf_buf addr_buf;
 
   offset = addr_index * addrsize + addr_base;
-  if (offset + addrsize >= dwarf_sections->size[DEBUG_ADDR])
+  if (offset + addrsize > dwarf_sections->size[DEBUG_ADDR])
     {
       error_callback (data, "DW_FORM_addrx value out of range", 0);
       return 0;