Skip to content

Commit

Permalink
Send EOF on stdout when exiting due to EOF on stdin
Browse files Browse the repository at this point in the history
Previously, if a service with exit-on-client-eof=true received EOF on
stdin while stdout was still open, no EOF would be sent on stdout.  This
is a (currently harmless) violation of the qrexec protocol.  Fix this by
sending an empty MSG_DATA_STDOUT to indicate EOF on stdout.

Fixes: QubesOS/qubes-issues#9429
  • Loading branch information
DemiMarie committed May 22, 2024
1 parent 3658079 commit 50bc9db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libqrexec/process_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ int qrexec_process_io(const struct process_io_request *req,
/* Convenience macros that eliminate a ton of error-prone boilerplate */
#define close_stdin() do { \
if (exit_on_stdin_eof) { \
/* If stdout is still open, send EOF */ \
if (stdout_fd != -1) { \
const struct msg_header hdr = { \
.type = stdout_msg_type, \
.len = 0, \
}; \
libvchan_send(vchan, &hdr, sizeof(hdr)); \
}; \
/* Set stdin_fd and stdout_fd to -1. \
* No need to close them as the process \
* will soon exit. */ \
Expand Down
1 change: 1 addition & 0 deletions qrexec/tests/socket/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ def test_connect_socket_exit_on_stdin_eof(self):
self.assertEqual(target.recv_all_messages(),
[
(qrexec.MSG_DATA_STDERR, b""),
(qrexec.MSG_DATA_STDOUT, b""),
(qrexec.MSG_DATA_EXIT_CODE, b"\0\0\0\0"),
])
self.check_dom0(dom0)
Expand Down

0 comments on commit 50bc9db

Please sign in to comment.