From: Wilfried Göesgens Date: Sat, 20 Feb 2010 14:16:03 +0000 (+0000) Subject: * found new bug in the RFC822 Decoder X-Git-Tag: v7.86~410 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=f9c96ea92107d5cbaa5466f57a65c673f5f0168b * found new bug in the RFC822 Decoder --- diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 502afd8b9..1029a34ac 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -2595,7 +2595,7 @@ void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* #endif const char *eptr; int passes = 0; - int i, len, delta; + int i, len; int illegal_non_rfc2047_encoding = 0; /* Sometimes, badly formed messages contain strings which were simply @@ -2692,22 +2692,16 @@ void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* (*ptr == '\n') || (*ptr == '\t'))) ptr ++; - /* did we find a gab just filled with blanks? */ - if (ptr == next) + /* + * did we find a gab just filled with blanks? + * if not, copy its stuff over. + */ + if (ptr != next) { - long gap = next - start; - memmove (end + 2, - next, - len - (gap)); - len -= gap; - /* now terminate the gab at the end */ - delta = (next - end) - 2; ////TODO: const! - ((StrBuf*)DecodeMee)->BufUsed -= delta; - ((StrBuf*)DecodeMee)->buf[DecodeMee->BufUsed] = '\0'; - - /* move next to its new location. */ - next -= delta; - nextend -= delta; + StrBufAppendBufPlain(Target, + end + 2, + next - end - 2, + 0); } } /* our next-pair is our new first pair now. */ diff --git a/libcitadel/tests/stringbuf_conversion.c b/libcitadel/tests/stringbuf_conversion.c index 5c7c36fbb..85ae46eec 100644 --- a/libcitadel/tests/stringbuf_conversion.c +++ b/libcitadel/tests/stringbuf_conversion.c @@ -88,6 +88,21 @@ static void TestRFC822Decode(void) FreeStrBuf(&Target); FreeStrBuf(&FoundCharset); FreeStrBuf(&DefaultCharset); + + + DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1")); + FoundCharset = NewStrBuf(); + Source = NewStrBufPlain(HKEY("\"w.goesgens\" , =?ISO-8859-15?Q?Walter_?= =?ISO-8859-15?Q?G=F6aoeus?= , =?ISO-8859-15?Q?aoeuaoeuh?= =?ISO-8859-15?Q?_G=F6aoeus?= , aoeuao aoeuaoeu %s<\n", ChrPtr(Target)); + FreeStrBuf(&Source); + FreeStrBuf(&Target); + FreeStrBuf(&FoundCharset); + FreeStrBuf(&DefaultCharset); + }