summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-04-29 13:38:32 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-04-29 13:38:32 +0300
commitb4b8b6ec832014c02a51cdcf4ce84bd38cc3f05f (patch)
tree8f9468138a56a3011dd1f046b6a0cc679aee2a72
parent21b82ef506c8be16a2022324cd3678a421b85a91 (diff)
downloadmailutils-b4b8b6ec832014c02a51cdcf4ce84bd38cc3f05f.tar.gz
mailutils-b4b8b6ec832014c02a51cdcf4ce84bd38cc3f05f.tar.bz2
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.
-rw-r--r--libproto/include/mime0.h1
-rw-r--r--mailbox/mime.c16
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));
}

Return to:

Send suggestions and report system problems to the System administrator.