]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: http-server-ostream - Make sure request payload input stream is destroyed...
authorStephan Bosch <stephan.bosch@open-xchange.com>
Thu, 23 Apr 2020 13:18:53 +0000 (15:18 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 27 Apr 2020 17:27:34 +0000 (17:27 +0000)
src/lib-http/http-server-ostream.c

index 335f676a38933ae993b8612d8dcbc7b71cbb01c8..58435611650bda436791f04bb75cd52afd979475 100644 (file)
@@ -1,6 +1,7 @@
 /* Copyright (c) 2018 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
+#include "istream.h"
 #include "dns-lookup.h"
 #include "ostream-wrapper.h"
 
@@ -186,7 +187,27 @@ http_server_ostream_wait_begin(struct wrapper_ostream *wostream,
 
        i_assert(hsostream->resp != NULL);
        i_assert(!hsostream->response_destroyed);
+
        http_server_connection_ref(conn);
+
+       /* When the response payload output stream is written from inside the
+          request callback, the incoming payload stream is not destroyed yet,
+          even though it is read to the end. This could lead to problems, so we
+          make an effort to destroy it here.
+        */
+       if (conn->incoming_payload != NULL) {
+               struct http_server_request *req = hsostream->resp->request;
+               struct istream *payload;
+
+               if (!i_stream_read_eof(conn->incoming_payload))
+                       i_unreached();
+               payload = req->req.payload;
+               req->req.payload = NULL;
+               i_stream_unref(&payload);
+
+               i_assert(conn->incoming_payload == NULL);
+       }
+
        prev_ioloop = http_server_connection_switch_ioloop_to(conn, ioloop);
        return prev_ioloop;
 }