[dovecot-cvs] dovecot/src/lib-index mail-index-update.c,1.51,1.52
mail-modifylog.c,1.45,1.46
cras at procontrol.fi
cras at procontrol.fi
Thu May 15 23:22:24 EEST 2003
Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv28191/lib-index
Modified Files:
mail-index-update.c mail-modifylog.c
Log Message:
Renamed buffer_*_space() to buffer_*_space_unsafe() and added several
warnings about using them. Fixed their usage in a few places in sources
where they could have produced invalid results (no buffer overflows,
luckily).
Index: mail-index-update.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-update.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- mail-index-update.c 27 Apr 2003 00:59:43 -0000 1.51
+++ mail-index-update.c 15 May 2003 19:22:22 -0000 1.52
@@ -130,13 +130,11 @@
static void *create_data_block(struct mail_index_update *update,
size_t data_size, size_t extra_size)
{
- struct mail_index_data_record_header *dest_hdr;
- struct mail_index_data_record *rec, *destrec;
+ struct mail_index_data_record *rec, destrec;
enum mail_data_field field;
buffer_t *buf;
const void *src;
- size_t src_size;
- size_t full_field_size;
+ size_t src_size, filler_size;
int i;
i_assert(data_size <= UINT_MAX);
@@ -144,16 +142,15 @@
buf = buffer_create_static_hard(update->pool, data_size);
/* set header */
- dest_hdr = buffer_append_space(buf, sizeof(*dest_hdr));
- memcpy(dest_hdr, &update->data_hdr, sizeof(*dest_hdr));
- dest_hdr->data_size = data_size;
+ update->data_hdr.data_size = data_size;
+ buffer_append(buf, &update->data_hdr, sizeof(update->data_hdr));
/* set fields */
rec = mail_index_data_lookup(update->index->data, update->rec, 0);
for (i = 0, field = 1; field != DATA_FIELD_LAST; i++, field <<= 1) {
if (update->fields[i] != NULL) {
/* value was modified - use it */
- full_field_size =
+ destrec.full_field_size =
get_max_align_size(update->field_sizes[i],
update->field_extra_sizes[i],
&extra_size);
@@ -161,20 +158,24 @@
src_size = update->field_sizes[i];
} else if (rec != NULL && rec->field == field) {
/* use the old value */
- full_field_size = rec->full_field_size;
+ destrec.full_field_size = rec->full_field_size;
src = rec->data;
src_size = rec->full_field_size;
} else {
/* the field doesn't exist, jump to next */
continue;
}
- i_assert((full_field_size % INDEX_ALIGN_SIZE) == 0);
+ i_assert((destrec.full_field_size % INDEX_ALIGN_SIZE) == 0);
- destrec = buffer_append_space(buf, SIZEOF_MAIL_INDEX_DATA +
- full_field_size);
- destrec->field = field;
- destrec->full_field_size = full_field_size;
- memcpy(destrec->data, src, src_size);
+ destrec.field = field;
+ buffer_append(buf, &destrec, SIZEOF_MAIL_INDEX_DATA);
+ buffer_append(buf, src, src_size);
+
+ filler_size = destrec.full_field_size - src_size;
+ if (filler_size != 0) {
+ buffer_set_used_size(buf, buffer_get_used_size(buf) +
+ filler_size);
+ }
if (rec != NULL && rec->field == field) {
rec = mail_index_data_next(update->index->data,
Index: mail-modifylog.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-modifylog.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- mail-modifylog.c 23 Apr 2003 13:23:14 -0000 1.45
+++ mail-modifylog.c 15 May 2003 19:22:22 -0000 1.46
@@ -1061,7 +1061,7 @@
unsigned int *expunges_before)
{
struct modify_log_record *rec;
- struct modify_log_expunge *expunge;
+ struct modify_log_expunge expunge, *expunges;
buffer_t *buf;
size_t count;
unsigned int before, max_records;
@@ -1118,19 +1118,18 @@
return NULL;
}
- expunge = buffer_append_space(buf, sizeof(*expunge));
-
if (rec->seq1 < first_seq) {
/* partial initial match, update
before-counter */
before += first_seq - rec->seq1;
- expunge->seq_count = rec->seq2 - first_seq + 1;
+ expunge.seq_count = rec->seq2 - first_seq + 1;
} else {
- expunge->seq_count = rec->seq2 - rec->seq1 + 1;
+ expunge.seq_count = rec->seq2 - rec->seq1 + 1;
}
- expunge->uid1 = rec->uid1;
- expunge->uid2 = rec->uid2;
+ expunge.uid1 = rec->uid1;
+ expunge.uid2 = rec->uid2;
+ buffer_append(buf, &expunge, sizeof(expunge));
}
if (rec->seq1 <= last_seq) {
@@ -1146,19 +1145,17 @@
}
/* terminate the array */
- expunge = buffer_append_space(buf, sizeof(*expunge));
- memset(expunge, 0, sizeof(*expunge));
+ buffer_set_used_size(buf, buffer_get_used_size(buf) + sizeof(expunge));
/* extract the array from buffer */
- count = buffer_get_used_size(buf)/sizeof(struct modify_log_expunge);
- expunge = buffer_free_without_data(buf);
+ count = buffer_get_used_size(buf) / sizeof(expunge);
+ expunges = buffer_free_without_data(buf);
/* sort the UID array, not including the terminating 0 */
- qsort(expunge, count-1, sizeof(struct modify_log_expunge),
- compare_expunge);
+ qsort(expunges, count-1, sizeof(expunge), compare_expunge);
*expunges_before = before;
- return expunge;
+ return expunges;
}
const struct modify_log_expunge *
@@ -1170,7 +1167,7 @@
/* pretty much copy&pasted from sequence code above ..
kind of annoying */
struct modify_log_record *rec;
- struct modify_log_expunge *expunge;
+ struct modify_log_expunge expunge, *expunges;
buffer_t *buf;
size_t count;
unsigned int before, max_records;
@@ -1227,28 +1224,25 @@
return NULL;
}
- expunge = buffer_append_space(buf, sizeof(*expunge));
-
- expunge->uid1 = rec->uid1;
- expunge->uid2 = rec->uid2;
- expunge->seq_count = rec->seq2 -rec->seq1 + 1;
+ expunge.uid1 = rec->uid1;
+ expunge.uid2 = rec->uid2;
+ expunge.seq_count = rec->seq2 -rec->seq1 + 1;
+ buffer_append(buf, &expunge, sizeof(expunge));
}
}
/* terminate the array */
- expunge = buffer_append_space(buf, sizeof(*expunge));
- memset(expunge, 0, sizeof(*expunge));
+ buffer_set_used_size(buf, buffer_get_used_size(buf) + sizeof(expunge));
/* extract the array from buffer */
- count = buffer_get_used_size(buf) / sizeof(struct modify_log_expunge);
- expunge = buffer_free_without_data(buf);
+ count = buffer_get_used_size(buf) / sizeof(expunge);
+ expunges = buffer_free_without_data(buf);
/* sort the UID array, not including the terminating 0 */
- qsort(expunge, count-1, sizeof(struct modify_log_expunge),
- compare_expunge);
+ qsort(expunges, count-1, sizeof(expunge), compare_expunge);
*expunges_before = before;
- return expunge;
+ return expunges;
}
static unsigned int
More information about the dovecot-cvs
mailing list