]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-fs: fs-metawrap - Don't try to write to an already finished ostream
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 31 Oct 2017 15:20:22 +0000 (17:20 +0200)
committerTimo Sirainen <tss@dovecot.fi>
Wed, 1 Nov 2017 00:22:19 +0000 (02:22 +0200)
Fixes a crash after recent changes when trying to write an empty file via
fs-metawrap.

src/lib-fs/fs-metawrap.c

index ae99da3f58096a0193ebd54a31619cf334d6199b..c62b9694acfb28755b903a7a191e93fa75544ec4 100644 (file)
@@ -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