dovecot-2.2: lib-compression: Add assert for LZ4_compress return...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Feb 5 01:17:57 EET 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/e30597858a66
changeset: 17131:e30597858a66
user: Teemu Huovila <teemu.huovila at dovecot.fi>
date: Tue Feb 04 18:17:35 2014 -0500
description:
lib-compression: Add assert for LZ4_compress return value.
Make certain we detect if compressed data overflows the allocated space.
diffstat:
src/lib-compression/ostream-lz4.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diffs (32 lines):
diff -r add8c00fb3cc -r e30597858a66 src/lib-compression/ostream-lz4.c
--- a/src/lib-compression/ostream-lz4.c Tue Feb 04 16:23:22 2014 -0500
+++ b/src/lib-compression/ostream-lz4.c Tue Feb 04 18:17:35 2014 -0500
@@ -18,7 +18,8 @@
unsigned int compressbuf_offset;
/* chunk size, followed by compressed data */
- unsigned char outbuf[IOSTREAM_LZ4_CHUNK_PREFIX_LEN + LZ4_COMPRESSBOUND(CHUNK_SIZE)];
+ unsigned char outbuf[IOSTREAM_LZ4_CHUNK_PREFIX_LEN +
+ LZ4_COMPRESSBOUND(CHUNK_SIZE)];
unsigned int outbuf_offset, outbuf_used;
};
@@ -70,11 +71,13 @@
i_assert(zstream->outbuf_offset == 0);
i_assert(zstream->outbuf_used == 0);
- zstream->outbuf_used = IOSTREAM_LZ4_CHUNK_PREFIX_LEN +
- LZ4_compress((void *)zstream->compressbuf,
- (void *)(zstream->outbuf + IOSTREAM_LZ4_CHUNK_PREFIX_LEN),
- zstream->compressbuf_offset);
- i_assert(zstream->outbuf_used > IOSTREAM_LZ4_CHUNK_PREFIX_LEN);
+ ret = LZ4_compress((void *)zstream->compressbuf,
+ (void *)(zstream->outbuf +
+ IOSTREAM_LZ4_CHUNK_PREFIX_LEN),
+ zstream->compressbuf_offset);
+ i_assert(ret > 0 && (unsigned int)ret <= sizeof(zstream->outbuf) -
+ IOSTREAM_LZ4_CHUNK_PREFIX_LEN);
+ zstream->outbuf_used = IOSTREAM_LZ4_CHUNK_PREFIX_LEN + ret;
chunk_size = zstream->outbuf_used - IOSTREAM_LZ4_CHUNK_PREFIX_LEN;
zstream->outbuf[0] = (chunk_size & 0xff000000) >> 24;
zstream->outbuf[1] = (chunk_size & 0x00ff0000) >> 16;
More information about the dovecot-cvs
mailing list