33d974
From ebcb61e3d88d99b929b4d8ccaad837a871c102d8 Mon Sep 17 00:00:00 2001
40f388
From: "Richard W.M. Jones" <rjones@redhat.com>
40f388
Date: Thu, 30 Oct 2014 13:50:39 +0000
214838
Subject: [PATCH 05/16] handle: Refuse to open files < 8192 bytes in size.
40f388
40f388
These cannot be valid hives, since they don't contain a full header
40f388
page and at least a single page of data (in other words they couldn't
40f388
contain a root node).
40f388
40f388
Thanks: Mahmoud Al-Qudsi
33d974
(cherry picked from commit 357f26fa64fd1d9ccac2331fe174a8ee9c607adb)
40f388
---
40f388
 lib/handle.c | 7 +++++++
40f388
 1 file changed, 7 insertions(+)
40f388
40f388
diff --git a/lib/handle.c b/lib/handle.c
40f388
index 62a8644..a3cbcf7 100644
40f388
--- a/lib/handle.c
40f388
+++ b/lib/handle.c
40f388
@@ -104,6 +104,13 @@ hivex_open (const char *filename, int flags)
40f388
 
40f388
   h->size = statbuf.st_size;
40f388
 
40f388
+  if (h->size < 0x2000) {
40f388
+    SET_ERRNO (EINVAL,
40f388
+               "%s: file is too small to be a Windows NT Registry hive file",
40f388
+               filename);
40f388
+    goto error;
40f388
+  }
40f388
+
40f388
   if (!h->writable) {
40f388
     h->addr = mmap (NULL, h->size, PROT_READ, MAP_SHARED, h->fd, 0);
40f388
     if (h->addr == MAP_FAILED)
40f388
-- 
33d974
1.8.3.1
40f388