From 5007f8c7942fb50b9263f3d151e4a11530021e90 Mon Sep 17 00:00:00 2001
From: Zachary T Welch <zwelch@codesourcery.com>
Date: Mon, 29 Nov 2010 20:10:07 -0800
Subject: [PATCH] Improve ELF valid_object() helper

Ensures the ELF header version is valid.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
---
 src/elfxx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/elfxx.c b/src/elfxx.c
index 06cc9bb6..7ed44bac 100644
--- a/src/elfxx.c
+++ b/src/elfxx.c
@@ -32,11 +32,13 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
 HIDDEN int
 elf_w (valid_object) (struct elf_image *ei)
 {
-  if (ei->size <= EI_CLASS)
+  if (ei->size <= EI_VERSION)
     return 0;
 
   return (memcmp (ei->image, ELFMAG, SELFMAG) == 0
-	  && ((uint8_t *) ei->image)[EI_CLASS] == ELF_CLASS);
+	  && ((uint8_t *) ei->image)[EI_CLASS] == ELF_CLASS
+	  && ((uint8_t *) ei->image)[EI_VERSION] != EV_NONE
+	  && ((uint8_t *) ei->image)[EI_VERSION] <= EV_CURRENT);
 }