ce257ff
From 4bbdf555f88baeae0fa804a369a81a83908bd705 Mon Sep 17 00:00:00 2001
ce257ff
From: "Richard W.M. Jones" <rjones@redhat.com>
ce257ff
Date: Thu, 30 Oct 2014 14:02:25 +0000
ce257ff
Subject: [PATCH 2/2] handle: Check that pages do not extend beyond the end of
ce257ff
 the file.
ce257ff
ce257ff
Thanks: Mahmoud Al-Qudsi
ce257ff
---
ce257ff
 lib/handle.c | 7 +++++++
ce257ff
 1 file changed, 7 insertions(+)
ce257ff
ce257ff
diff --git a/lib/handle.c b/lib/handle.c
ce257ff
index a3cbcf7..3a8f09b 100644
ce257ff
--- a/lib/handle.c
ce257ff
+++ b/lib/handle.c
ce257ff
@@ -247,6 +247,13 @@ hivex_open (const char *filename, int flags)
ce257ff
       goto error;
ce257ff
     }
ce257ff
 
ce257ff
+    if (off + page_size > h->size) {
ce257ff
+      SET_ERRNO (ENOTSUP,
ce257ff
+                 "%s: page size %zu at 0x%zx extends beyond end of file, bad registry",
ce257ff
+                 filename, page_size, off);
ce257ff
+      goto error;
ce257ff
+    }
ce257ff
+
ce257ff
     /* Read the blocks in this page. */
ce257ff
     size_t blkoff;
ce257ff
     struct ntreg_hbin_block *block;
ce257ff
-- 
ce257ff
2.1.0
ce257ff