[gmime: 7/8] Fixed header parsing logic when dealing with input in DOS format
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime: 7/8] Fixed header parsing logic when dealing with input in DOS format
- Date: Fri, 3 Nov 2017 14:35:56 +0000 (UTC)
commit 0e5ffc8206da1d5a1197585b0fdbce1009d467a6
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date: Fri Nov 3 10:24:35 2017 -0400
Fixed header parsing logic when dealing with input in DOS format
When the input is in DOS format, the <CR> of the blank line
terminating the headers would be appended to priv->headerbuf
and then, after breaking out of the loop, it would be parsed
as a header (which, of course, would fail and so be set as
priv->preheader and later message->marker).
This would then cause writing out of message/rfc822 parts
to be written with a marker of "\r" (+ the newline sequence
specified by the GMimeFormatOptions).
Fixes issue #23
gmime/gmime-parser.c | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/gmime/gmime-parser.c b/gmime/gmime-parser.c
index 1c4ba0a..5e365f4 100644
--- a/gmime/gmime-parser.c
+++ b/gmime/gmime-parser.c
@@ -901,6 +901,10 @@ header_parse (GMimeParser *parser)
(long long) priv->header_offset,
priv->headerbuf));
+ printf ("Invalid header at %lld: '%s'",
+ (long long) priv->header_offset,
+ priv->headerbuf);
+
if (priv->preheader == NULL)
priv->preheader = g_strdup (priv->headerbuf);
@@ -996,6 +1000,9 @@ parser_step_headers (GMimeParser *parser)
priv->headers_begin = parser_offset (priv, NULL);
priv->header_offset = priv->headers_begin;
+ priv->headerleft += priv->headerptr - priv->headerbuf;
+ priv->headerptr = priv->headerbuf;
+
inptr = priv->inptr;
inend = priv->inend;
@@ -1113,8 +1120,6 @@ parser_step_headers (GMimeParser *parser)
goto refill;
}
- header_append (priv, start, len);
-
if (inptr > start && inptr[-1] == '\r')
len--;
@@ -1122,8 +1127,13 @@ parser_step_headers (GMimeParser *parser)
if (!priv->midline && len == 0)
goto headers_end;
- /* inptr has to be less than inend - 1 */
- header_append (priv, "\n", 1);
+ if (inptr > start && inptr[-1] == '\r')
+ len++;
+
+ /* increment len to include the \n */
+ len++;
+
+ header_append (priv, start, len);
priv->midline = FALSE;
continuation = TRUE;
inptr++;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]