fix buffer overrun while converting charsets
authorWilfried Goesgens <dothebart@citadel.org>
Wed, 10 Nov 2010 19:22:16 +0000 (20:22 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Wed, 10 Nov 2010 19:26:53 +0000 (20:26 +0100)
* DecodeSegment() didn't check whether one of the temporary buffers would be able to bear the transcoding results

libcitadel/lib/stringbuf.c

index 5c538310feea86600e0f333423f56ea322e02d32..ed17a0a0cb3504e8773a5dc13ddf29d68122b1d3 100644 (file)
@@ -2850,6 +2850,8 @@ inline static void DecodeSegment(StrBuf *Target,
        
        *encoding = toupper(*encoding);
        if (*encoding == 'B') { /**< base64 */
+               if (ConvertBuf2->BufSize < ConvertBuf->BufUsed)
+                       IncreaseBuf(ConvertBuf2, 0, ConvertBuf->BufUsed);
                ConvertBuf2->BufUsed = CtdlDecodeBase64(ConvertBuf2->buf, 
                                                        ConvertBuf->buf, 
                                                        ConvertBuf->BufUsed);
@@ -2865,6 +2867,9 @@ inline static void DecodeSegment(StrBuf *Target,
                        pos++;
                }
                
+               if (ConvertBuf2->BufSize < ConvertBuf->BufUsed)
+                       IncreaseBuf(ConvertBuf2, 0, ConvertBuf->BufUsed);
+
                ConvertBuf2->BufUsed = CtdlDecodeQuotedPrintable(
                        ConvertBuf2->buf, 
                        ConvertBuf->buf,