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.
Showing
2 changed files
with
13 additions
and
4 deletions
... | @@ -71,6 +71,7 @@ struct _mu_mime | ... | @@ -71,6 +71,7 @@ struct _mu_mime |
71 | /* parser state */ | 71 | /* parser state */ |
72 | char *cur_line; | 72 | char *cur_line; |
73 | int line_ndx; | 73 | int line_ndx; |
74 | size_t line_size; | ||
74 | char *cur_buf; | 75 | char *cur_buf; |
75 | int buf_size; | 76 | int buf_size; |
76 | char *header_buf; | 77 | char *header_buf; | ... | ... |
... | @@ -224,7 +224,7 @@ _mime_setup_buffers (mu_mime_t mime) | ... | @@ -224,7 +224,7 @@ _mime_setup_buffers (mu_mime_t mime) |
224 | return ENOMEM; | 224 | return ENOMEM; |
225 | } | 225 | } |
226 | if (mime->cur_line == NULL | 226 | if (mime->cur_line == NULL |
227 | && (mime->cur_line = calloc (MIME_MAX_HDR_LEN, 1)) == NULL) | 227 | && (mime->cur_line = calloc (mime->line_size, 1)) == NULL) |
228 | { | 228 | { |
229 | free (mime->cur_buf); | 229 | free (mime->cur_buf); |
230 | return ENOMEM; | 230 | return ENOMEM; |
... | @@ -380,10 +380,17 @@ _mime_parse_mpart_message (mu_mime_t mime) | ... | @@ -380,10 +380,17 @@ _mime_parse_mpart_message (mu_mime_t mime) |
380 | } | 380 | } |
381 | } | 381 | } |
382 | mime->line_ndx++; | 382 | mime->line_ndx++; |
383 | if (mime->line_ndx >= MIME_MAX_HDR_LEN) | 383 | if (mime->line_ndx >= mime->line_size) |
384 | { | 384 | { |
385 | mime->line_ndx = 0; | 385 | size_t newsize = mime->line_size + MIME_MAX_HDR_LEN; |
386 | mime->parser_state = MIME_STATE_BEGIN_LINE; | 386 | char *p = realloc (mime->cur_line, newsize); |
387 | if (!p) | ||
388 | { | ||
389 | ret = ENOMEM; | ||
390 | break; | ||
391 | } | ||
392 | mime->cur_line = p; | ||
393 | mime->line_size = newsize; | ||
387 | } | 394 | } |
388 | mime->cur_offset++; | 395 | mime->cur_offset++; |
389 | nbytes--; | 396 | nbytes--; |
... | @@ -806,6 +813,7 @@ mu_mime_create (mu_mime_t *pmime, mu_message_t msg, int flags) | ... | @@ -806,6 +813,7 @@ mu_mime_create (mu_mime_t *pmime, mu_message_t msg, int flags) |
806 | { | 813 | { |
807 | mime->msg = msg; | 814 | mime->msg = msg; |
808 | mime->buf_size = MIME_DFLT_BUF_SIZE; | 815 | mime->buf_size = MIME_DFLT_BUF_SIZE; |
816 | mime->line_size = MIME_MAX_HDR_LEN; | ||
809 | mu_message_get_body (msg, &body); | 817 | mu_message_get_body (msg, &body); |
810 | mu_body_get_stream (body, &(mime->stream)); | 818 | mu_body_get_stream (body, &(mime->stream)); |
811 | } | 819 | } | ... | ... |
-
Please register or sign in to post a comment