summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2021-12-19 23:58:32 +0100
committerMark Wielaard <mark@klomp.org>2021-12-19 23:58:32 +0100
commit34ef8b44ed5998b025bd77fde4c71d7d8e585cf0 (patch)
treea9297a1db37dd827ba156c73b67bfae75d7482e3 /libdwfl
parentlibdwfl: Rewrite GElf_Nhdr reading in dwfl_segment_report_module (diff)
downloadelfutils-34ef8b44ed5998b025bd77fde4c71d7d8e585cf0.tar.gz
elfutils-34ef8b44ed5998b025bd77fde4c71d7d8e585cf0.tar.bz2
elfutils-34ef8b44ed5998b025bd77fde4c71d7d8e585cf0.tar.xz
libdwfl: Handle unaligned Ehdr in dwfl_segment_report_module
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). Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog5
-rw-r--r--libdwfl/dwfl_segment_report_module.c14
2 files changed, 19 insertions, 0 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 18ffc347..6c7e0c4a 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,10 @@
12021-12-19 Mark Wielaard <mark@klomp.org> 12021-12-19 Mark Wielaard <mark@klomp.org>
2 2
3 * dwfl_segment_report_module.c (dwfl_segment_report_module): Copy
4 buffer and set xlatefrom.d_buf to ehdr when buffer is not aligned.
5
62021-12-19 Mark Wielaard <mark@klomp.org>
7
3 * dwfl_segment_report_module.c (dwfl_segment_report_module): Check 8 * dwfl_segment_report_module.c (dwfl_segment_report_module): Check
4 notes filesz. Rewrite reading of GElf_Nhdr. 9 notes filesz. Rewrite reading of GElf_Nhdr.
5 10
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index a6d6be85..7f756392 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -367,6 +367,20 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
367 e_ident = ((const unsigned char *) buffer); 367 e_ident = ((const unsigned char *) buffer);
368 ei_class = e_ident[EI_CLASS]; 368 ei_class = e_ident[EI_CLASS];
369 ei_data = e_ident[EI_DATA]; 369 ei_data = e_ident[EI_DATA];
370 /* buffer may be unaligned, in which case xlatetom would not work.
371 xlatetom does work when the in and out d_buf are equal (but not
372 for any other overlap). */
373 size_t ehdr_align = (ei_class == ELFCLASS32
374 ? __alignof__ (Elf32_Ehdr)
375 : __alignof__ (Elf64_Ehdr));
376 if (((uintptr_t) buffer & (ehdr_align - 1)) != 0)
377 {
378 memcpy (&ehdr, buffer,
379 (ei_class == ELFCLASS32
380 ? sizeof (Elf32_Ehdr)
381 : sizeof (Elf64_Ehdr)));
382 xlatefrom.d_buf = &ehdr;
383 }
370 switch (ei_class) 384 switch (ei_class)
371 { 385 {
372 case ELFCLASS32: 386 case ELFCLASS32: