From: Mark Wielaard <mjw@redhat.com>
To: elfutils-devel@lists.fedorahosted.org
Subject: Re: [PATCH] readelf: Fix cie_offset calculation comparison on 32bit.
Date: Tue, 28 Apr 2015 14:15:08 +0200 [thread overview]
Message-ID: <1430223308.1938.187.camel@bordewijk.wildebeest.org> (raw)
In-Reply-To: 1429699846-2117-1-git-send-email-mjw@redhat.com
[-- Attachment #1: Type: text/plain, Size: 624 bytes --]
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 <mjw@redhat.com>
>
> + * 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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-readelf-Fix-cie_offset-calculation-comparison-on-32b.patch --]
[-- Type: text/x-patch, Size: 1707 bytes --]
From 32d5b6f61a90b3c0c777b73eee973d6816a21294 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mjw@redhat.com>
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 <mjw@redhat.com>
---
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 <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
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
next reply other threads:[~2015-04-28 12:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-28 12:15 Mark Wielaard [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-04-22 10:50 Mark Wielaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1430223308.1938.187.camel@bordewijk.wildebeest.org \
--to=mjw@redhat.com \
--cc=elfutils-devel@lists.fedorahosted.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).