]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Don't assume auxv or r_debug data is properly aligned in link_map.
authorMark Wielaard <mjw@redhat.com>
Sun, 31 May 2015 18:49:23 +0000 (20:49 +0200)
committerMark Wielaard <mjw@redhat.com>
Fri, 5 Jun 2015 12:52:29 +0000 (14:52 +0200)
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
libdwfl/link_map.c

index ffb34c034c0a0394ec56b000464ece16a531667e..f4e7484b5bab2388e272b266b9e7f13d3aa0d0da 100644 (file)
@@ -1,3 +1,10 @@
+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
index a5a6968729fb293bf42696679701e3bfc8b594e5..030c6002aa02bc4f537da820dad8ad0e14720fe3 100644 (file)
@@ -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;