diff mbox series

libdwfl: Calculate addr to read by hand in link_map.c read_addrs.

Message ID 20211224010608.1302841-1-mark@klomp.org
State Committed
Headers show
Series libdwfl: Calculate addr to read by hand in link_map.c read_addrs. | expand

Commit Message

Mark Wielaard Dec. 24, 2021, 1:06 a.m. UTC
The gcc undefined sanitizer doesn't like the trick we use to calculate
the (possibly) unaligned addresses to read. So calculate them by hand
as unsigned char pointers.

https://sourceware.org/bugzilla/show_bug.cgi?id=28720

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libdwfl/ChangeLog  |  4 ++++
 libdwfl/link_map.c | 11 +++++------
 2 files changed, 9 insertions(+), 6 deletions(-)

Comments

Mark Wielaard Jan. 3, 2022, 11:40 p.m. UTC | #1
On Fri, Dec 24, 2021 at 02:06:08AM +0100, Mark Wielaard wrote:
> The gcc undefined sanitizer doesn't like the trick we use to calculate
> the (possibly) unaligned addresses to read. So calculate them by hand
> as unsigned char pointers.
> 
> https://sourceware.org/bugzilla/show_bug.cgi?id=28720

Pushed
diff mbox series

Patch

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 73d8613c..149383ad 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,7 @@ 
+2021-12-23  Mark Wielaard  <mark@klomp.org>
+
+	* link_map.c (read_addrs): Calculate addr to read by hand.
+
 2021-12-23  Mark Wielaard  <mark@klomp.org>
 
 	* link_map.c (dwfl_link_map_report): Call memcpy and set in.d_buf to
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index f57c5585..cd9c5042 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -270,26 +270,25 @@  read_addrs (struct memory_closure *closure,
 	return true;
     }
 
-  Elf32_Addr (*a32)[n] = vaddr - (*read_vaddr) + (*buffer);
-  Elf64_Addr (*a64)[n] = (void *) a32;
+  unsigned char *addr = vaddr - (*read_vaddr) + (*buffer);
 
   if (elfclass == ELFCLASS32)
     {
       if (elfdata == ELFDATA2MSB)
 	for (size_t i = 0; i < n; ++i)
-	  addrs[i] = BE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
+	  addrs[i] = BE32 (read_4ubyte_unaligned_noncvt (addr + i * 4));
       else
 	for (size_t i = 0; i < n; ++i)
-	  addrs[i] = LE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
+	  addrs[i] = LE32 (read_4ubyte_unaligned_noncvt (addr + i * 4));
     }
   else
     {
       if (elfdata == ELFDATA2MSB)
 	for (size_t i = 0; i < n; ++i)
-	  addrs[i] = BE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
+	  addrs[i] = BE64 (read_8ubyte_unaligned_noncvt (addr + i * 8));
       else
 	for (size_t i = 0; i < n; ++i)
-	  addrs[i] = LE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
+	  addrs[i] = LE64 (read_8ubyte_unaligned_noncvt (addr + i * 8));
     }
 
   return false;