]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-compression: ostream-zlib - Require o_stream_finish() to write the trailer
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 27 Oct 2017 23:09:58 +0000 (02:09 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Mon, 30 Oct 2017 11:04:53 +0000 (13:04 +0200)
It's now possible to call o_stream_flush() without the trailer getting
written.

It's also now required to call o_stream_finish() to write the trailer before
closing the ostream. This guarantees that the caller checks that the
trailer was successfully written. This isn't needed if the ostream already
failed before writing the trailer.

src/lib-compression/ostream-zlib.c
src/lib-compression/test-compression.c

index 2851762de67bcb2b8e7bef383de6963fd774f72d..b2b3bde338bef9737d5b080b6f4b024b0de32532 100644 (file)
@@ -32,7 +32,8 @@ static void o_stream_zlib_close(struct iostream_private *stream,
 {
        struct zlib_ostream *zstream = (struct zlib_ostream *)stream;
 
-       (void)o_stream_flush(&zstream->ostream.ostream);
+       i_assert(zstream->ostream.finished ||
+                zstream->ostream.ostream.stream_errno != 0);
        (void)deflateEnd(&zstream->zs);
        if (close_parent)
                o_stream_close(zstream->ostream.parent);
@@ -230,7 +231,7 @@ static int o_stream_zlib_flush(struct ostream_private *stream)
        struct zlib_ostream *zstream = (struct zlib_ostream *)stream;
        int ret;
 
-       if (o_stream_zlib_send_flush(zstream, TRUE) < 0)
+       if (o_stream_zlib_send_flush(zstream, stream->finished) < 0)
                return -1;
 
        ret = o_stream_flush(stream->parent);
index ff1658c7bf58f3e90c2ad23a04172239e3ce51ee..5dbe6db94f10d26c34d9ce816518714843a8700a 100644 (file)
@@ -62,6 +62,7 @@ static void test_compression_handler(const struct compression_handler *handler)
                test_assert(o_stream_send(output, buf, sizeof(buf)) == sizeof(buf));
        }
 
+       test_assert(o_stream_finish(output) > 0);
        o_stream_destroy(&output);
        o_stream_destroy(&file_output);
        sha1_result(&sha1, output_sha1);