core file data isn't guaranteed to be alligned properly. Use read_(4|8)ubyte_unaligned_noncvt to read values, types and addresses.
Signed-off-by: Mark Wielaard mjw@redhat.com --- libdwfl/ChangeLog | 7 +++++++ libdwfl/link_map.c | 25 +++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index ffb34c0..f4e7484 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,12 @@ 2015-05-30 Mark Wielaard mjw@redhat.com
+ * link_map.c (check32): Use read_4ubyte_unaligned_noncvt to read + type and value. + (read_addrs): Use read_(4|8)ubyte_unaligned_noncvt or to read + adresses. + +2015-05-30 Mark Wielaard mjw@redhat.com + * find-debuginfo.c (dwfl_standard_find_debuginfo): Check file_name is not NULL before calling canonicalize_file_name.
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c index a5a6968..030c600 100644 --- a/libdwfl/link_map.c +++ b/libdwfl/link_map.c @@ -58,8 +58,7 @@ auxv_format_probe (const void *auxv, size_t size, inline bool check64 (size_t i) { /* The AUXV pointer might not even be naturally aligned for 64-bit - data, because note payloads in a core file are not aligned. - But we assume the data is 32-bit aligned. */ + data, because note payloads in a core file are not aligned. */
uint64_t type = read_8ubyte_unaligned_noncvt (&u->a64[i].a_type); uint64_t val = read_8ubyte_unaligned_noncvt (&u->a64[i].a_un.a_val); @@ -83,15 +82,21 @@ auxv_format_probe (const void *auxv, size_t size,
inline bool check32 (size_t i) { - if (u->a32[i].a_type == BE32 (PROBE_TYPE) - && u->a32[i].a_un.a_val == BE32 (PROBE_VAL32)) + /* The AUXV pointer might not even be naturally aligned for 32-bit + data, because note payloads in a core file are not aligned. */ + + uint32_t type = read_4ubyte_unaligned_noncvt (&u->a32[i].a_type); + uint32_t val = read_4ubyte_unaligned_noncvt (&u->a32[i].a_un.a_val); + + if (type == BE32 (PROBE_TYPE) + && val == BE32 (PROBE_VAL32)) { *elfdata = ELFDATA2MSB; return true; }
- if (u->a32[i].a_type == LE32 (PROBE_TYPE) - && u->a32[i].a_un.a_val == LE32 (PROBE_VAL32)) + if (type == LE32 (PROBE_TYPE) + && val == LE32 (PROBE_VAL32)) { *elfdata = ELFDATA2LSB; return true; @@ -285,19 +290,19 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata, { if (elfdata == ELFDATA2MSB) for (size_t i = 0; i < n; ++i) - addrs[i] = BE32 (in->a32[i]); + addrs[i] = BE32 (read_4ubyte_unaligned_noncvt (&in->a32[i])); else for (size_t i = 0; i < n; ++i) - addrs[i] = LE32 (in->a32[i]); + addrs[i] = LE32 (read_4ubyte_unaligned_noncvt (&in->a32[i])); } else { if (elfdata == ELFDATA2MSB) for (size_t i = 0; i < n; ++i) - addrs[i] = BE64 (in->a64[i]); + addrs[i] = BE64 (read_8ubyte_unaligned_noncvt (&in->a64[i])); else for (size_t i = 0; i < n; ++i) - addrs[i] = LE64 (in->a64[i]); + addrs[i] = LE64 (read_8ubyte_unaligned_noncvt (&in->a64[i])); }
return false;
elfutils-devel@lists.fedorahosted.org