From 99d9db00b886b29b961b63d94424321be3ddfca5 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Mon, 7 Jan 2013 13:01:10 -0800 Subject: [PATCH] elf_getarsym: Use memcpy instead of pointer dereference so as not to assume the field is naturally aligned. Signed-off-by: Roland McGrath --- libelf/ChangeLog | 5 +++++ libelf/elf_getarsym.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 4a9e35810..23e1a8674 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2013-01-07 Roland McGrath + + * 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 * elf.h: Update from glibc. diff --git a/libelf/elf_getarsym.c b/libelf/elf_getarsym.c index 9e0f4c2bb..ffdd8ada0 100644 --- a/libelf/elf_getarsym.c +++ b/libelf/elf_getarsym.c @@ -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; -- 2.47.2