From 3f29b411d0a022bb4272316a50feb57aa8ef90ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 10 May 2015 03:37:40 +0200 Subject: [PATCH] qrexec: do not send spurious MSG_SERVICE_REFUSED This causes closing connection (FD) to still alive client. Fixes qubesos/qubes-issues#993 --- qrexec/qrexec-daemon.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/qrexec/qrexec-daemon.c b/qrexec/qrexec-daemon.c index 37c8182..cf41f04 100644 --- a/qrexec/qrexec-daemon.c +++ b/qrexec/qrexec-daemon.c @@ -397,6 +397,7 @@ static int handle_cmdline_body_from_client(int fd, struct msg_header *hdr) int len = hdr->len-sizeof(params); char buf[len]; int use_default_user = 0; + int i; if (!read_all(fd, ¶ms, sizeof(params))) { terminate_client(fd); @@ -407,6 +408,22 @@ static int handle_cmdline_body_from_client(int fd, struct msg_header *hdr) return 0; } + if (hdr->type == MSG_SERVICE_CONNECT) { + /* if the service was accepted, do not send spurious + * MSG_SERVICE_REFUSED when service process itself exit with non-zero + * code */ + for (i = 0; i <= policy_pending_max; i++) { + if (policy_pending[i].pid && + strncmp(policy_pending[i].params.ident, buf, len) == 0) { + policy_pending[i].pid = 0; + while (policy_pending_max > 0 && + policy_pending[policy_pending_max].pid > 0) + policy_pending_max--; + break; + } + } + } + if (!params.connect_port) { struct exec_params client_params; /* allocate port and send it to the client */