From: Timo Sirainen Date: Thu, 8 May 2003 00:49:02 +0000 (+0300) Subject: FETCH BODY[HEADER.FIELDS ...] now doesn't crash to assert if header line X-Git-Tag: 1.1.alpha1~4673 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69ea3d8c18f48ab9762443112dda36a521e8642f;p=thirdparty%2Fdovecot%2Fcore.git FETCH BODY[HEADER.FIELDS ...] now doesn't crash to assert if header line contains NULs. IMAP spec actually forbids sending NULs to client, uw-imapd changes them to ascii 128. Currently we send them though, that requires some more fixing. --HG-- branch : HEAD --- diff --git a/src/imap/imap-fetch-body-section.c b/src/imap/imap-fetch-body-section.c index de12e3d975..ba49ec2aa6 100644 --- a/src/imap/imap-fetch-body-section.c +++ b/src/imap/imap-fetch-body-section.c @@ -1,7 +1,7 @@ /* Copyright (C) 2002 Timo Sirainen */ #include "common.h" -#include "str.h" +#include "buffer.h" #include "istream.h" #include "ostream.h" #include "message-parser.h" @@ -20,7 +20,7 @@ #define MAX_HEADER_BUFFER_SIZE (32*1024) struct fetch_header_field_context { - string_t *dest; + buffer_t *dest; struct ostream *output; uoff_t dest_size; @@ -207,7 +207,7 @@ static int fetch_header_append(struct fetch_header_field_context *ctx, } if (ctx->dest != NULL) - str_append_n(ctx->dest, str, size); + buffer_append(ctx->dest, str, size); ctx->dest_size += size; if (ctx->output != NULL) { @@ -264,7 +264,8 @@ static int fetch_header_fields(struct istream *input, const char *section, message_parse_header_deinit(hdr_ctx); i_assert(ctx->dest_size <= ctx->max_size); - i_assert(ctx->dest == NULL || str_len(ctx->dest) == ctx->dest_size); + i_assert(ctx->dest == NULL || + buffer_get_used_size(ctx->dest) == ctx->dest_size); return TRUE; } @@ -277,6 +278,8 @@ static int fetch_header_from(struct imap_fetch_context *ctx, { struct fetch_header_field_context hdr_ctx; const char *str; + const void *data; + size_t data_size; uoff_t start_offset; int failed; @@ -313,8 +316,10 @@ static int fetch_header_from(struct imap_fetch_context *ctx, i_assert(hdr_ctx.dest_size <= size->virtual_size); } else { - hdr_ctx.dest = t_str_new(size->virtual_size < 8192 ? - size->virtual_size : 8192); + hdr_ctx.dest = + buffer_create_dynamic(data_stack_pool, + I_MIN(size->virtual_size, 8192), + (size_t)-1); if (!fetch_header_fields(input, header_section, &hdr_ctx)) failed = TRUE; } @@ -341,8 +346,8 @@ static int fetch_header_from(struct imap_fetch_context *ctx, i_assert(first_size == hdr_ctx.dest_size); } else { - if (o_stream_send(ctx->output, str_data(hdr_ctx.dest), - str_len(hdr_ctx.dest)) < 0) + data = buffer_get_data(hdr_ctx.dest, &data_size); + if (o_stream_send(ctx->output, data, data_size) < 0) failed = TRUE; } }