On Wed, 2015-04-22 at 12:50 +0200, Mark Wielaard wrote: > 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. > > 2015-03-22 Mark Wielaard <[email protected]> > > + * readelf.c (print_debug_frame_section): Cast start to Dwarf_Off > + before subtracting cie_id.
That wasn't completely correct on 64bit. We also need to explicitly cast cie_offset to Dwarf_Off. Pushed with that fixed as attached.
From 32d5b6f61a90b3c0c777b73eee973d6816a21294 Mon Sep 17 00:00:00 2001 From: Mark Wielaard <[email protected]> Date: Wed, 22 Apr 2015 12:47:46 +0200 Subject: [PATCH] readelf: Fix cie_offset calculation comparison on 32bit. 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 <[email protected]> --- src/ChangeLog | 6 ++++++ src/readelf.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 40a0e6f..a4ac4e4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2015-03-22 Mark Wielaard <[email protected]> + * 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 <[email protected]> + * readelf.c (print_gdb_index_section): Check all offsets used against section d_size. diff --git a/src/readelf.c b/src/readelf.c index 26c7eed..b4cb3a8 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -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; -- 1.8.3.1
