From b4b8b6ec832014c02a51cdcf4ce84bd38cc3f05f Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Thu, 29 Apr 2010 13:38:32 +0300 Subject: Remove line length limitation in mime parser. * libproto/include/mime0.h (struct _mu_mime): New member line_size. * mailbox/mime.c (_mime_setup_buffers): Use line_size instead of MIME_MAX_HDR_LEN. (_mime_parse_mpart_message): Reallocate cur_line as necessary. (mu_mime_create): Initialize line_size. --- libproto/include/mime0.h | 1 + mailbox/mime.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libproto/include/mime0.h b/libproto/include/mime0.h index 145db33bb..f002353ed 100644 --- a/libproto/include/mime0.h +++ b/libproto/include/mime0.h @@ -71,6 +71,7 @@ struct _mu_mime /* parser state */ char *cur_line; int line_ndx; + size_t line_size; char *cur_buf; int buf_size; char *header_buf; diff --git a/mailbox/mime.c b/mailbox/mime.c index 421d6862d..33186d91d 100644 --- a/mailbox/mime.c +++ b/mailbox/mime.c @@ -224,7 +224,7 @@ _mime_setup_buffers (mu_mime_t mime) return ENOMEM; } if (mime->cur_line == NULL - && (mime->cur_line = calloc (MIME_MAX_HDR_LEN, 1)) == NULL) + && (mime->cur_line = calloc (mime->line_size, 1)) == NULL) { free (mime->cur_buf); return ENOMEM; @@ -380,10 +380,17 @@ _mime_parse_mpart_message (mu_mime_t mime) } } mime->line_ndx++; - if (mime->line_ndx >= MIME_MAX_HDR_LEN) + if (mime->line_ndx >= mime->line_size) { - mime->line_ndx = 0; - mime->parser_state = MIME_STATE_BEGIN_LINE; + size_t newsize = mime->line_size + MIME_MAX_HDR_LEN; + char *p = realloc (mime->cur_line, newsize); + if (!p) + { + ret = ENOMEM; + break; + } + mime->cur_line = p; + mime->line_size = newsize; } mime->cur_offset++; nbytes--; @@ -806,6 +813,7 @@ mu_mime_create (mu_mime_t *pmime, mu_message_t msg, int flags) { mime->msg = msg; mime->buf_size = MIME_DFLT_BUF_SIZE; + mime->line_size = MIME_MAX_HDR_LEN; mu_message_get_body (msg, &body); mu_body_get_stream (body, &(mime->stream)); } -- cgit v1.2.1