INN commit: branches/2.5/storage/tradindexed (tdx-group.c)

INN Commit rra at isc.org
Thu May 14 13:44:15 UTC 2015


    Date: Thursday, May 14, 2015 @ 06:44:14
  Author: iulius
Revision: 9867

Correct remap check in tradindexed lookup

The check was off by one; and when it happened, it invalidated the
'parent' pointer, causing a use-after-munmap (or use-after-free)
condition.

Thanks to Richard Kettlewell for the bug report.

Modified:
  branches/2.5/storage/tradindexed/tdx-group.c

-------------+
 tdx-group.c |   17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

Modified: tdx-group.c
===================================================================
--- tdx-group.c	2015-05-14 13:43:28 UTC (rev 9866)
+++ tdx-group.c	2015-05-14 13:44:14 UTC (rev 9867)
@@ -358,7 +358,7 @@
        their next entry is entry 0.  We don't want to leave things in this
        state (particularly if this was the first expansion of the index file,
        in which case entry 0 points to entry 0 and our walking functions may
-       go into infinite loops.  Undo the file expansion. */
+       go into infinite loops).  Undo the file expansion. */
     if (!index_map(index)) {
         index->count -= 1024;
         if (ftruncate(index->fd, index_file_size(index->count)) < 0) {
@@ -557,11 +557,20 @@
     parent = &index->header->hash[index_bucket(hash)].recno;
     current = *parent;
 
-    while (current >= 0 && current < index->count) {
+    while (current >= 0) {
         struct group_entry *entry;
 
-        if (current > index->count && !index_maybe_remap(index, current))
-            return -1;
+        if (current >= index->count) {
+            if (!index_maybe_remap(index, current)) {
+                return -1;
+            }
+            parent = &index->header->hash[index_bucket(hash)].recno;
+            current = *parent;
+            if (current < 0 || current >= index->count) {
+                syswarn("tradindexed: entry %ld out of range", current);
+                return -1;
+            }
+        }
         entry = &index->entries[current];
         if (entry->deleted == 0)
             if (memcmp(&hash, &entry->hash, sizeof(hash)) == 0) {



More information about the inn-committers mailing list