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:24:57 +0000 (20:24 +0100)
* DecodeSegment() didn't check whether one of the temporary buffers would be able to bear the transcoding results

libcitadel/lib/stringbuf.c

index 5d050e7502d0c1adec4a38ff134c3a949df335b6..88cea7d704681a9490a25264a2b7aa40883c4d84 100644 (file)
@@ -2945,6 +2945,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);
@@ -2960,6 +2962,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,