]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
login-common: Fix potential crash when login proxy is destroyed
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 27 Jun 2025 21:23:14 +0000 (00:23 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Sat, 28 Jun 2025 16:19:49 +0000 (16:19 +0000)
iostream-proxy may have closed the proxy with istream first, which closed
the fd, followed by closing the ostream, which attempted to remove IO for
the already closed fd.

Use iostream_fd refcounting to make sure the fd isn't closed too early.

Fixes:
Panic: epoll_ctl(del, 22) failed: Bad file descriptor

src/login-common/client-common.c

index 6e1dad13bd34de1ca264f128523ab1b0410d4eb3..bb5b948c7fc013c0bccd9f9792ed621c52c3a225 100644 (file)
@@ -923,9 +923,10 @@ int client_get_plaintext_fd(struct client *client, int *fd_r, bool *close_fd_r)
        fd_set_nonblock(fds[0], TRUE);
        fd_set_nonblock(fds[1], TRUE);
 
-       struct ostream *output = o_stream_create_fd(fds[0], IO_BLOCK_SIZE);
-       struct istream *input =
-               i_stream_create_fd_autoclose(&fds[0], IO_BLOCK_SIZE);
+       struct ostream *output;
+       struct istream *input;
+       io_stream_create_fd_autoclose(&fds[0], IO_BLOCK_SIZE, IO_BLOCK_SIZE,
+                                     &input, &output);
        o_stream_set_no_error_handling(output, TRUE);
 
        i_assert(client->io == NULL);