Some entries in /proc/<pid>/maps are not ELF files, so add checks
in elf_map_image() to ensure mapped files have a valid ELF header.

Signed-off-by: Zachary T Welch <[email protected]>
---
 src/elfxx.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/elfxx.h b/src/elfxx.h
index 7742806..cdc3f58 100644
--- a/src/elfxx.h
+++ b/src/elfxx.h
@@ -46,6 +46,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.  */
 static inline int
 elf_map_image (struct elf_image *ei, const char *path)
 {
+  Elf_W (Ehdr) *ehdr;
   struct stat stat;
   int fd;
 
@@ -65,6 +66,13 @@ elf_map_image (struct elf_image *ei, const char *path)
   if (ei->image == MAP_FAILED)
     return -1;
 
+  ehdr = ei->image;
+  if (strncmp(ehdr->e_ident, "\x7f" "ELF", 4) != 0)
+    return -1;
+
+  if (ehdr->e_version == EV_NONE || ehdr->e_version > EV_CURRENT)
+    return -1;
+
   return 0;
 }
 
-- 
1.7.2.2


_______________________________________________
Libunwind-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/libunwind-devel

Reply via email to