[dovecot-cvs] dovecot/src/lib-mail message-body-search.c,1.5,1.6 message-header-search.c,1.8,1.9 message-size.c,1.8,1.9 message-size.h,1.5,1.6 rfc822-tokenize.c,1.5,1.6
cras at procontrol.fi
cras at procontrol.fi
Wed Dec 18 17:15:44 EET 2002
Update of /home/cvs/dovecot/src/lib-mail
In directory danu:/tmp/cvs-serv3676/src/lib-mail
Modified Files:
message-body-search.c message-header-search.c message-size.c
message-size.h rfc822-tokenize.c
Log Message:
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
cleanups and a couple of minor bugfixes.
Index: message-body-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-body-search.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- message-body-search.c 16 Dec 2002 03:59:06 -0000 1.5
+++ message-body-search.c 18 Dec 2002 15:15:41 -0000 1.6
@@ -32,9 +32,7 @@
CharsetTranslation *translation;
Buffer *decode_buf;
-
- size_t *matches;
- ssize_t match_count;
+ Buffer *match_buf;
char *content_type;
char *content_charset;
@@ -156,30 +154,31 @@
static int message_search_decoded_block(PartSearchContext *ctx, Buffer *block)
{
const unsigned char *p, *end, *key;
- size_t key_len, block_size;
+ size_t key_len, block_size, *matches, match_count, value;
ssize_t i;
key = (const unsigned char *) ctx->body_ctx->key;
key_len = ctx->body_ctx->key_len;
+ matches = buffer_get_modifyable_data(ctx->match_buf, &match_count);
+ match_count /= sizeof(size_t);
+
p = buffer_get_data(block, &block_size);
end = p + block_size;
for (; p != end; p++) {
- for (i = ctx->match_count-1; i >= 0; i--) {
- if (key[ctx->matches[i]] == *p) {
- if (++ctx->matches[i] == key_len) {
+ for (i = match_count-1; i >= 0; i--) {
+ if (key[matches[i]] == *p) {
+ if (++matches[i] == key_len) {
/* full match */
p++;
return TRUE;
}
} else {
/* non-match */
- ctx->match_count--;
- if (i != ctx->match_count) {
- memmove(ctx->matches + i,
- ctx->matches + i + 1,
- ctx->match_count - i);
- }
+ buffer_delete(ctx->match_buf,
+ i * sizeof(size_t),
+ sizeof(size_t));
+ match_count--;
}
}
@@ -190,8 +189,9 @@
return TRUE;
}
- i_assert((size_t)ctx->match_count < key_len);
- ctx->matches[ctx->match_count++] = 1;
+ value = 1;
+ buffer_append(ctx->match_buf, &value, sizeof(value));
+ match_count++;
}
}
@@ -284,9 +284,9 @@
ctx->translation = charset_to_utf8_begin("ascii", NULL);
ctx->decode_buf = buffer_create_static(data_stack_pool, 256);
-
- ctx->match_count = 0;
- ctx->matches = t_malloc(sizeof(size_t) * ctx->body_ctx->key_len);
+ ctx->match_buf = buffer_create_static_hard(data_stack_pool,
+ sizeof(size_t) *
+ ctx->body_ctx->key_len);
i_stream_skip(input, part->physical_pos +
part->header_size.physical_size - input->v_offset);
Index: message-header-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-header-search.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- message-header-search.c 16 Dec 2002 03:59:06 -0000 1.8
+++ message-header-search.c 18 Dec 2002 15:15:41 -0000 1.9
@@ -18,8 +18,7 @@
size_t key_len;
char *key_charset;
- size_t *matches; /* size of strlen(key) */
- ssize_t match_count;
+ Buffer *match_buf;
unsigned int found:1;
unsigned int last_newline:1;
@@ -48,7 +47,6 @@
if (key == NULL) {
/* invalid key */
- t_pop();
return NULL;
}
@@ -66,7 +64,8 @@
}
i_assert(ctx->key_len <= SSIZE_T_MAX/sizeof(size_t));
- ctx->matches = p_new(pool, size_t, ctx->key_len);
+ ctx->match_buf = buffer_create_static_hard(pool, sizeof(size_t) *
+ ctx->key_len);
return ctx;
}
@@ -74,10 +73,11 @@
{
Pool pool;
+ buffer_free(ctx->match_buf);
+
pool = ctx->pool;
p_free(pool, ctx->key);
p_free(pool, ctx->key_charset);
- p_free(pool, ctx->matches);
p_free(pool, ctx);
}
@@ -112,11 +112,14 @@
static void search_loop(const unsigned char *data, size_t size,
HeaderSearchContext *ctx)
{
- size_t pos;
+ size_t pos, *matches, match_count, value;
ssize_t i;
unsigned char chr;
int last_newline;
+ matches = buffer_get_modifyable_data(ctx->match_buf, &match_count);
+ match_count /= sizeof(size_t);
+
last_newline = ctx->last_newline;
for (pos = 0; pos < size; pos++) {
chr = data[pos];
@@ -137,7 +140,8 @@
if (last_newline && !ctx->submatch) {
if (!IS_LWSP(chr)) {
/* not a long header, reset matches */
- ctx->match_count = 0;
+ buffer_set_used_size(ctx->match_buf, 0);
+ match_count = 0;
}
chr = ' ';
}
@@ -146,21 +150,19 @@
if (chr == '\r' || chr == '\n')
continue;
- for (i = ctx->match_count-1; i >= 0; i--) {
- if (ctx->key[ctx->matches[i]] == chr) {
- if (++ctx->matches[i] == ctx->key_len) {
+ for (i = match_count-1; i >= 0; i--) {
+ if (ctx->key[matches[i]] == chr) {
+ if (++matches[i] == ctx->key_len) {
/* full match */
ctx->found = TRUE;
return;
}
} else {
/* non-match */
- ctx->match_count--;
- if (i != ctx->match_count) {
- memmove(ctx->matches + i,
- ctx->matches + i + 1,
- ctx->match_count - i);
- }
+ buffer_delete(ctx->match_buf,
+ i * sizeof(size_t),
+ sizeof(size_t));
+ match_count--;
}
}
@@ -170,8 +172,10 @@
ctx->found = TRUE;
break;
}
- i_assert((size_t)ctx->match_count < ctx->key_len);
- ctx->matches[ctx->match_count++] = 1;
+
+ value = 1;
+ buffer_append(ctx->match_buf, &value, sizeof(value));
+ match_count++;
}
}
@@ -205,6 +209,6 @@
void message_header_search_reset(HeaderSearchContext *ctx)
{
- ctx->match_count = 0;
+ buffer_set_used_size(ctx->match_buf, 0);
ctx->found = FALSE;
}
Index: message-size.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-size.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- message-size.c 6 Dec 2002 01:09:23 -0000 1.8
+++ message-size.c 18 Dec 2002 15:15:41 -0000 1.9
@@ -161,7 +161,7 @@
}
}
-void message_size_add(MessageSize *dest, MessageSize *src)
+void message_size_add(MessageSize *dest, const MessageSize *src)
{
dest->virtual_size += src->virtual_size;
dest->physical_size += src->physical_size;
Index: message-size.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-size.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- message-size.h 6 Dec 2002 01:09:23 -0000 1.5
+++ message-size.h 18 Dec 2002 15:15:41 -0000 1.6
@@ -18,6 +18,6 @@
MessageSize *msg_size, int *cr_skipped);
/* Sum contents of src into dest. */
-void message_size_add(MessageSize *dest, MessageSize *src);
+void message_size_add(MessageSize *dest, const MessageSize *src);
#endif
Index: rfc822-tokenize.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/rfc822-tokenize.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- rfc822-tokenize.c 2 Dec 2002 13:49:16 -0000 1.5
+++ rfc822-tokenize.c 18 Dec 2002 15:15:41 -0000 1.6
@@ -23,6 +23,7 @@
{
Rfc822Token *token;
+ /* @UNSAFE */
if (*pos+1 >= INITIAL_COUNT)
*tokens = t_buffer_reget_type(*tokens, Rfc822Token, *pos + 2);
@@ -180,6 +181,7 @@
if (tokens_count != NULL)
*tokens_count = pos;
+ /* @UNSAFE */
first_token[pos++].token = 0;
t_buffer_alloc(sizeof(Rfc822Token) * pos);
return first_token;
@@ -187,6 +189,7 @@
const char *rfc822_tokens_get_value(const Rfc822Token *tokens, int count)
{
+ /* @UNSAFE */
char *buf;
size_t i, len, buf_size;
int last_atom;
@@ -249,6 +252,7 @@
const char *rfc822_tokens_get_value_quoted(const Rfc822Token *tokens,
int count)
{
+ /* @UNSAFE */
char *buf;
size_t len, buf_size;
int last_atom;
More information about the dovecot-cvs
mailing list