]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: istream-try - Don't assert-crash with empty parent istream
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 8 Jun 2018 20:17:04 +0000 (23:17 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Fri, 25 Jan 2019 09:24:43 +0000 (11:24 +0200)
Fixes:
Panic: file istream.c: line 327 (i_stream_read_memarea): assertion failed: (stream->eof)

src/lib/istream-try.c
src/lib/test-istream-try.c

index 4284f6d17a20a6042ee11ed49ddcf33bed1d2c45..0e9b78ad0903533d07fab72f552c4ba05a19e1d2 100644 (file)
@@ -76,6 +76,11 @@ static int i_stream_try_detect(struct try_istream *tstream)
                }
                if (ret == 0)
                        return 0;
+               if (try_input->stream_errno == 0) {
+                       /* empty file */
+                       tstream->istream.istream.eof = TRUE;
+                       return -1;
+               }
                if (try_input->stream_errno != EINVAL) {
                        tstream->istream.istream.stream_errno =
                                try_input->stream_errno;
index 39a4185e7365250674802a747264531c9bf9e0d4..91ac37ddd16a999f6f31fa1037c4a1a04ffc6e0d 100644 (file)
@@ -4,7 +4,7 @@
 #include "istream.h"
 #include "istream-try.h"
 
-void test_istream_try(void)
+static void test_istream_try_normal(void)
 {
        bool finished = FALSE;
 
@@ -128,3 +128,27 @@ void test_istream_try(void)
        i_assert(finished);
        test_end();
 }
+
+static void test_istream_try_empty(void)
+{
+       test_begin("istream try empty stream");
+       struct istream *test_inputs[] = {
+               test_istream_create(""),
+               test_istream_create(""),
+               NULL
+       };
+       struct istream *try_input = istream_try_create(test_inputs);
+       test_assert(i_stream_read(try_input) == -1);
+       test_assert(try_input->eof);
+       test_assert(try_input->stream_errno == 0);
+       i_stream_unref(&test_inputs[0]);
+       i_stream_unref(&test_inputs[1]);
+       i_stream_unref(&try_input);
+       test_end();
+}
+
+void test_istream_try(void)
+{
+       test_istream_try_normal();
+       test_istream_try_empty();
+}