]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-ssl-iostream: iostream-openssl - Use o_stream_uncork_flush() to uncork the plain...
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 23 Sep 2020 20:02:41 +0000 (22:02 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 30 Sep 2021 17:08:11 +0000 (17:08 +0000)
This flushes the stream after uncorking it, fixing I/O hang with nested SSL
layers.

src/lib-ssl-iostream/iostream-openssl.c

index 156cb7e40122089c11b2501411864ab653e769c0..e1a8d31b6f7f3746cff03055be728b660c7fb4e0 100644 (file)
@@ -391,7 +391,7 @@ static void openssl_iostream_destroy(struct ssl_iostream *ssl_io)
 
 static int openssl_iostream_bio_output_real(struct ssl_iostream *ssl_io)
 {
-       size_t bytes, max_bytes;
+       size_t bytes, max_bytes = 0;
        ssize_t sent;
        unsigned char buffer[IO_BLOCK_SIZE];
        int result = 0;
@@ -405,8 +405,6 @@ static int openssl_iostream_bio_output_real(struct ssl_iostream *ssl_io)
                if (bytes > max_bytes) {
                        if (max_bytes == 0) {
                                /* wait until output buffer clears */
-                               o_stream_set_flush_pending(ssl_io->plain_output,
-                                                          TRUE);
                                break;
                        }
                        bytes = max_bytes;
@@ -430,7 +428,13 @@ static int openssl_iostream_bio_output_real(struct ssl_iostream *ssl_io)
                i_assert(sent == (ssize_t)bytes);
                result = 1;
        }
-       o_stream_uncork(ssl_io->plain_output);
+
+       ret = o_stream_uncork_flush(ssl_io->plain_output);
+       if (ret < 0)
+               return -1;
+       if (ret == 0 || (bytes > 0 && max_bytes == 0))
+               o_stream_set_flush_pending(ssl_io->plain_output, TRUE);
+
        return result;
 }