comparison src/lib-index/mail-index.c @ 228:a97509eb0bc3 HEAD

always verify the seen/deleted message counts in index header
author Timo Sirainen <tss@iki.fi>
date Sun, 15 Sep 2002 10:12:31 +0300
parents ca6967899c05
children 9ef72cb26b30
comparison
equal deleted inserted replaced
227:2499dad2932b 228:a97509eb0bc3
16 #include <fcntl.h> 16 #include <fcntl.h>
17 #include <utime.h> 17 #include <utime.h>
18 18
19 static int mmap_verify(MailIndex *index) 19 static int mmap_verify(MailIndex *index)
20 { 20 {
21 MailIndexHeader *hdr;
21 unsigned int extra; 22 unsigned int extra;
22 23
23 index->mmap_used_length = 0; 24 index->mmap_used_length = 0;
24 25
25 if (index->mmap_full_length < sizeof(MailIndexHeader)) { 26 if (index->mmap_full_length < sizeof(MailIndexHeader)) {
40 } 41 }
41 42
42 index->last_lookup_seq = 0; 43 index->last_lookup_seq = 0;
43 index->last_lookup = NULL; 44 index->last_lookup = NULL;
44 45
45 index->header = (MailIndexHeader *) index->mmap_base; 46 hdr = index->mmap_base;
46 index->sync_id = index->header->sync_id; 47 index->header = hdr;
47 48 index->sync_id = hdr->sync_id;
48 if (index->header->used_file_size > index->mmap_full_length) { 49
50 if (hdr->used_file_size > index->mmap_full_length) {
49 index_set_corrupted(index, "used_file_size larger than real " 51 index_set_corrupted(index, "used_file_size larger than real "
50 "file size (%"PRIuUOFF_T" vs %"PRIuSIZE_T 52 "file size (%"PRIuUOFF_T" vs %"PRIuSIZE_T
51 ")", index->header->used_file_size, 53 ")", hdr->used_file_size,
52 index->mmap_full_length); 54 index->mmap_full_length);
53 return FALSE; 55 return FALSE;
54 } 56 }
55 57
56 if ((index->header->used_file_size - sizeof(MailIndexHeader)) % 58 if ((hdr->used_file_size - sizeof(MailIndexHeader)) %
57 sizeof(MailIndexRecord) != 0) { 59 sizeof(MailIndexRecord) != 0) {
58 index_set_corrupted(index, "Invalid used_file_size in header " 60 index_set_corrupted(index, "Invalid used_file_size in header "
59 "(%"PRIuUOFF_T")", 61 "(%"PRIuUOFF_T")",
60 index->header->used_file_size); 62 hdr->used_file_size);
61 return FALSE; 63 return FALSE;
62 } 64 }
63 65
64 index->mmap_used_length = index->header->used_file_size; 66 if (hdr->messages_count < hdr->seen_messages_count) {
67 index_set_corrupted(index, "Invalid seen messages count "
68 "(%u < %u)", hdr->messages_count,
69 hdr->seen_messages_count);
70 return FALSE;
71 }
72
73 if (hdr->messages_count < hdr->deleted_messages_count) {
74 index_set_corrupted(index, "Invalid deleted messages count "
75 "(%u < %u)", hdr->messages_count,
76 hdr->deleted_messages_count);
77 return FALSE;
78 }
79
80 index->mmap_used_length = hdr->used_file_size;
65 return TRUE; 81 return TRUE;
66 } 82 }
67 83
68 static int mmap_update(MailIndex *index) 84 static int mmap_update(MailIndex *index)
69 { 85 {