This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH] readelf: Fix cie_offset calculation comparison on 32bit.
- From: Mark Wielaard <mjw at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Wed, 22 Apr 2015 12:50: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 <mjw@redhat.com>
---
src/ChangeLog | 5 +++++
src/readelf.c | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/ChangeLog b/src/ChangeLog
index 40a0e6f..6a1aa40 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
2015-03-22 Mark Wielaard <mjw@redhat.com>
+ * readelf.c (print_debug_frame_section): Cast start to Dwarf_Off
+ before subtracting cie_id.
+
+2015-03-22 Mark Wielaard <mjw@redhat.com>
+
* 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..550b00d 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) == cie->cie_offset
+ : cie_id == cie->cie_offset)
break;
else
cie = cie->next;
--
2.1.0