elf_getarsym: Use memcpy instead of pointer dereference so as not to assume the field...
authorRoland McGrath <roland@hack.frob.com>
Mon, 7 Jan 2013 21:01:10 +0000 (13:01 -0800)
committerRoland McGrath <roland@hack.frob.com>
Mon, 7 Jan 2013 21:01:10 +0000 (13:01 -0800)
Signed-off-by: Roland McGrath <roland@hack.frob.com>
libelf/ChangeLog
libelf/elf_getarsym.c

index 4a9e358..23e1a86 100644 (file)
@@ -1,3 +1,8 @@
+2013-01-07  Roland McGrath  <roland@hack.frob.com>
+
+       * elf_getarsym.c (read_number_entries): Use memcpy instead of pointer
+       dereference so as not to assume the field is naturally aligned.
+
 2012-09-17  Petr Machata  <pmachata@redhat.com>
 
        * elf.h: Update from glibc.
index 9e0f4c2..ffdd8ad 100644 (file)
@@ -57,7 +57,9 @@ read_number_entries (uint64_t *nump, Elf *elf, size_t *offp, bool index64_p)
 
   size_t w = index64_p ? 8 : 4;
   if (elf->map_address != NULL)
-    u = *(union u *) (elf->map_address + *offp);
+    /* Use memcpy instead of pointer dereference so as not to assume the
+       field is naturally aligned within the file.  */
+    memcpy (&u, elf->map_address + *offp, sizeof u);
   else if ((size_t) pread_retry (elf->fildes, &u, w, *offp) != w)
     return -1;