* calculate the compressed buffer more effective so we can avaid integer overflows...
authorWilfried Göesgens <willi@citadel.org>
Tue, 21 Jul 2009 22:10:28 +0000 (22:10 +0000)
committerWilfried Göesgens <willi@citadel.org>
Tue, 21 Jul 2009 22:10:28 +0000 (22:10 +0000)
* if we fail the malloc, return -1

libcitadel/lib/stringbuf.c

index 1cc92269a4878c2985a008727640fa1f2f3daddb..f682cb686bbeb1903fcbf8c6e01e9c2a5d980c40 100644 (file)
@@ -2236,10 +2236,12 @@ int CompressBuffer(StrBuf *Buf)
        char *compressed_data = NULL;
        size_t compressed_len, bufsize;
        int i = 0;
-       
-       bufsize = compressed_len = ((Buf->BufUsed * 101) / 100) + 100;
+
+       bufsize = compressed_len = Buf->BufUsed +  (Buf->BufUsed / 100) + 100;
        compressed_data = malloc(compressed_len);
        
+       if (compressed_data == NULL)
+               return -1;
        /* Flush some space after the used payload so valgrind shuts up... */
         while ((i < 10) && (Buf->BufUsed + i < Buf->BufSize))
                Buf->buf[Buf->BufUsed + i++] = '\0';