]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Index fsck crashfix / cleanup.
authorTimo Sirainen <tss@iki.fi>
Mon, 4 Aug 2008 21:04:40 +0000 (17:04 -0400)
committerTimo Sirainen <tss@iki.fi>
Mon, 4 Aug 2008 21:04:40 +0000 (17:04 -0400)
--HG--
branch : HEAD

src/lib-index/mail-index-fsck.c

index 24d7e020474bf41ab4ed32e79319b7e4d436bb2d..60558d6389ed568df5e5c3226096f0078e51e3e0 100644 (file)
@@ -261,20 +261,24 @@ mail_index_fsck_extensions(struct mail_index *index, struct mail_index_map *map,
        const struct mail_index_ext_header *ext_hdr;
        ARRAY_TYPE(const_string) names;
        const char *name, *error;
-       unsigned int offset, ext_offset, i;
+       unsigned int offset, next_offset, i;
 
        t_array_init(&names, 64);
        offset = MAIL_INDEX_HEADER_SIZE_ALIGN(hdr->base_header_size);
        for (i = 0; offset < hdr->header_size; i++) {
-               ext_offset = offset;
-               if (mail_index_map_ext_get_next(map, &offset,
+               /* mail_index_map_ext_get_next() uses map->hdr, so make sure
+                  it's up-to-date */
+               map->hdr = *hdr;
+
+               next_offset = offset;
+               if (mail_index_map_ext_get_next(map, &next_offset,
                                                &ext_hdr, &name) < 0) {
                        /* the extension continued outside header, drop it */
                        mail_index_fsck_error(index,
                                              "Dropped extension #%d (%s) "
                                              "with invalid header size",
                                              i, name);
-                       hdr->header_size = ext_offset;
+                       hdr->header_size = offset;
                        break;
                }
                if (mail_index_map_ext_hdr_check(hdr, ext_hdr, name,
@@ -290,20 +294,20 @@ mail_index_fsck_extensions(struct mail_index *index, struct mail_index_map *map,
 
                        if (strcmp(name, "keywords") == 0) {
                                mail_index_fsck_keywords(index, map, hdr,
-                                                        ext_hdr, ext_offset,
-                                                        &offset);
+                                                        ext_hdr, offset,
+                                                        &next_offset);
                        }
                        array_append(&names, &name, 1);
                        continue;
                }
 
                /* drop the field */
-               hdr->header_size -= offset - ext_offset;
-               buffer_copy(map->hdr_copy_buf, ext_offset,
-                           map->hdr_copy_buf, offset, (size_t)-1);
+               hdr->header_size -= next_offset - offset;
+               buffer_copy(map->hdr_copy_buf, offset,
+                           map->hdr_copy_buf, next_offset, (size_t)-1);
                buffer_set_used_size(map->hdr_copy_buf, hdr->header_size);
                map->hdr_base = map->hdr_copy_buf->data;
-               offset = ext_offset;
+               next_offset = offset;
        }
 }