]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Fix cie_offset calculation comparison on 32bit.
authorMark Wielaard <mjw@redhat.com>
Wed, 22 Apr 2015 10:47:46 +0000 (12:47 +0200)
committerMark Wielaard <mjw@redhat.com>
Tue, 28 Apr 2015 12:14:09 +0000 (14:14 +0200)
gcc -fsanitize=undefined pointed out that on 32bit systems the calculation
to match the cie_offset to the cie_id could be undefined because a cie_id
could be an unsigned 64bit value while ptrdiff_t is only 32bits. Correct
the calculation to use 64bit values.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
src/ChangeLog
src/readelf.c

index 40a0e6f97599bfa9e13b01617914341834332fdb..a4ac4e469cff300f5e4a363882dbd4243fee9c1d 100644 (file)
@@ -1,3 +1,9 @@
+2015-03-22  Mark Wielaard  <mjw@redhat.com>
+
+       * readelf.c (print_debug_frame_section): Cast start to Dwarf_Off
+       before subtracting cie_id. And cast cie_offset to Dwarf_Off before
+       comparison.
+
 2015-03-22  Mark Wielaard  <mjw@redhat.com>
 
        * readelf.c (print_gdb_index_section): Check all offsets used
index 26c7eedb53e26611fe27617766f489642c51653a..b4cb3a827495b885df72b504edbbf36f79685892 100644 (file)
@@ -5619,8 +5619,8 @@ print_debug_frame_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
          struct cieinfo *cie = cies;
          while (cie != NULL)
            if (is_eh_frame
-               ? start - (ptrdiff_t) cie_id == cie->cie_offset
-               : (ptrdiff_t) cie_id == cie->cie_offset)
+               ? ((Dwarf_Off) start - cie_id) == (Dwarf_Off) cie->cie_offset
+               : cie_id == (Dwarf_Off) cie->cie_offset)
              break;
            else
              cie = cie->next;