summaryrefslogtreecommitdiffstats
path: root/libdwfl/link_map.c
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2015-05-31 20:49:23 +0200
committerMark Wielaard <[email protected]>2015-06-05 14:52:29 +0200
commit616489da5005c63fe572df422f1936529c4743f5 (patch)
treeb2ff764c3ad5362d7c7cc3b37cbf534999a8a5f9 /libdwfl/link_map.c
parent96f6c995ff041c7c874179f7542b244713e54570 (diff)
libdwfl: Don't assume auxv or r_debug data is properly aligned in link_map.
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 <[email protected]>
Diffstat (limited to 'libdwfl/link_map.c')
-rw-r--r--libdwfl/link_map.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index a5a69687..030c6002 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;