Some entries in /proc/<pid>/maps are not ELF files, so add check
in elf_map_image() to ensure mapped files have a valid ELF header.
Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
Signed-off-by: Arun Sharma <asharma@fb.com>
diff --git a/src/elfxx.h b/src/elfxx.h
index 7742806..e316970 100644
--- a/src/elfxx.h
+++ b/src/elfxx.h
@@ -43,6 +43,12 @@
# define elf_w(x) _Uelf64_##x
#endif
+extern int elf_w (valid_object) (struct elf_image *ei);
+extern int elf_w (get_proc_name) (unw_addr_space_t as,
+ pid_t pid, unw_word_t ip,
+ char *buf, size_t len,
+ unw_word_t *offp);
+
static inline int
elf_map_image (struct elf_image *ei, const char *path)
{
@@ -65,11 +71,11 @@
if (ei->image == MAP_FAILED)
return -1;
+ if (!elf_w (valid_object) (ei))
+ {
+ munmap(ei->image, ei->size);
+ return -1;
+ }
+
return 0;
}
-
-extern int elf_w (valid_object) (struct elf_image *ei);
-extern int elf_w (get_proc_name) (unw_addr_space_t as,
- pid_t pid, unw_word_t ip,
- char *buf, size_t len,
- unw_word_t *offp);