]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Handle unaligned Nhdr in dwfl_segment_report_module
authorMark Wielaard <mark@klomp.org>
Mon, 20 Dec 2021 00:39:21 +0000 (01:39 +0100)
committerMark Wielaard <mark@klomp.org>
Mon, 20 Dec 2021 00:44:49 +0000 (01:44 +0100)
The xlate functions only handle correctly aligned buffers. But they do
handle src == dest. So if the source buffer isn't aligned correctly
just copy it first into the destination (which is already correctly
aligned).

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdwfl/ChangeLog
libdwfl/dwfl_segment_report_module.c

index ac0fbe0f7cd3ef2bd748411d04b32499fb43f852..6015f6b7e844afc7bba7a6deb175d5d80d10bd35 100644 (file)
@@ -1,3 +1,8 @@
+2021-12-19  Mark Wielaard  <mark@klomp.org>
+
+       * dwfl_segment_report_module.c (dwfl_segment_report_module): Copy
+       data and set xlatefrom.d_buf to notes when data is not aligned.
+
 2021-12-19  Mark Wielaard  <mark@klomp.org>
 
        * dwfl_segment_report_module.c (dwfl_segment_report_module): Copy
index de190e906290a76520d7746faf5097e8c9ae6c8e..72c850706783103887edee08df2233d6d2ca542b 100644 (file)
@@ -573,6 +573,18 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
                   xlatefrom.d_size = filesz;
                   xlateto.d_buf = notes;
                   xlateto.d_size = filesz;
+
+                 /* data may be unaligned, in which case xlatetom would not work.
+                    xlatetom does work when the in and out d_buf are equal (but not
+                    for any other overlap).  */
+                 if ((uintptr_t) data != (align == 8
+                                          ? NOTE_ALIGN8 ((uintptr_t) data)
+                                          : NOTE_ALIGN4 ((uintptr_t) data)))
+                   {
+                     memcpy (notes, data, filesz);
+                     xlatefrom.d_buf = notes;
+                   }
+
                   if (elf32_xlatetom (&xlateto, &xlatefrom, xencoding) == NULL)
                     {
                       free (notes);