diff options
Diffstat (limited to 'libdwfl')
-rw-r--r-- | libdwfl/ChangeLog | 5 | ||||
-rw-r--r-- | libdwfl/dwfl_segment_report_module.c | 14 |
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 @@ | |||
1 | 2021-12-19 Mark Wielaard <mark@klomp.org> | 1 | 2021-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 | |||
6 | 2021-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: |