From 8f00bdb4a6441e1110809052f174af7f232c4449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 17 Mar 2015 12:39:30 +0100 Subject: [PATCH] qrexec: process vchan data queue (esp MSG_EXIT_CODE) before sending anything In case of remote process exit even when some messages are still waiting, vchan connection can be already closed. If we try to send some data in this case (for example stdout of local process), there will be an error, which will terminate qrexec-client-vm/qrexec-agent child. So first check vchan data (where could be MSG_EXIT_CODE queued) , then local process. There is still some race condition in this code - remote process could exit just after we check vchan, but before we send some data. But this is much less probable and in the worst case we only loose remote process exit code. --- qrexec/qrexec-agent-data.c | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/qrexec/qrexec-agent-data.c b/qrexec/qrexec-agent-data.c index fe9b57f..5bf9739 100644 --- a/qrexec/qrexec-agent-data.c +++ b/qrexec/qrexec-agent-data.c @@ -361,26 +361,6 @@ int process_child_io(libvchan_t *data_vchan, handle_vchan_error("wait"); } - if (stdout_fd >= 0 && FD_ISSET(stdout_fd, &rdset)) { - switch (handle_input(data_vchan, stdout_fd, stdout_msg_type)) { - case -1: - handle_vchan_error("send"); - break; - case 0: - stdout_fd = -1; - break; - } - } - if (stderr_fd >= 0 && FD_ISSET(stderr_fd, &rdset)) { - switch (handle_input(data_vchan, stderr_fd, MSG_DATA_STDERR)) { - case -1: - handle_vchan_error("send"); - break; - case 0: - stderr_fd = -1; - break; - } - } /* handle_remote_data will check if any data is available */ switch (handle_remote_data(data_vchan, stdin_fd, &remote_process_status)) { case -1: @@ -403,6 +383,26 @@ int process_child_io(libvchan_t *data_vchan, return remote_process_status; break; } + if (stdout_fd >= 0 && FD_ISSET(stdout_fd, &rdset)) { + switch (handle_input(data_vchan, stdout_fd, stdout_msg_type)) { + case -1: + handle_vchan_error("send"); + break; + case 0: + stdout_fd = -1; + break; + } + } + if (stderr_fd >= 0 && FD_ISSET(stderr_fd, &rdset)) { + switch (handle_input(data_vchan, stderr_fd, MSG_DATA_STDERR)) { + case -1: + handle_vchan_error("send"); + break; + case 0: + stderr_fd = -1; + break; + } + } } return child_process_status; }