public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH] readelf: Fix cie_offset calculation comparison on 32bit.
@ 2015-04-28 12:15 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2015-04-28 12:15 UTC (permalink / raw)
  To: elfutils-devel

[-- 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] readelf: Fix cie_offset calculation comparison on 32bit.
@ 2015-04-22 10:50 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2015-04-22 10:50 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 1399 bytes --]

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-28 12:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-28 12:15 [PATCH] readelf: Fix cie_offset calculation comparison on 32bit Mark Wielaard
  -- strict thread matches above, loose matches on Subject: below --
2015-04-22 10:50 Mark Wielaard

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).