From: Timo Sirainen Date: Tue, 31 Oct 2017 15:20:22 +0000 (+0200) Subject: lib-fs: fs-metawrap - Don't try to write to an already finished ostream X-Git-Tag: 2.3.0.rc1~668 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=03e102ddccaae9e944c503d4269de755731798e8;p=thirdparty%2Fdovecot%2Fcore.git lib-fs: fs-metawrap - Don't try to write to an already finished ostream Fixes a crash after recent changes when trying to write an empty file via fs-metawrap. --- diff --git a/src/lib-fs/fs-metawrap.c b/src/lib-fs/fs-metawrap.c index ae99da3f58..c62b9694ac 100644 --- a/src/lib-fs/fs-metawrap.c +++ b/src/lib-fs/fs-metawrap.c @@ -391,10 +391,16 @@ static int fs_metawrap_write_stream_finish(struct fs_file *_file, bool success) } /* finish writing the temporary file */ if (file->temp_output->offset == 0) { - /* empty file */ - fs_metawrap_write_metadata_to(file, file->temp_output); + /* empty file - temp_output is already finished, + so we can't write to it. */ + string_t *str = t_str_new(128); + + o_stream_destroy(&file->temp_output); + fs_metawrap_append_metadata(file, str); + input = i_stream_create_copy_from_data(str_data(str), str_len(str)); + } else { + input = iostream_temp_finish(&file->temp_output, IO_BLOCK_SIZE); } - input = iostream_temp_finish(&file->temp_output, IO_BLOCK_SIZE); if (file->metadata_changed_since_write) { /* we'll need to recreate the metadata. do this by creating a new istream combining the new metadata header and the