Skip to content

Commit

Permalink
agent: fix error path on failed service exec
Browse files Browse the repository at this point in the history
(cherry-picked from fixes by Marek Marczykowski-Górecki)

If service fails to start, exit instead of trying to handle
(non-existing) process.
  • Loading branch information
pwmarcz committed Mar 6, 2020
1 parent 80002db commit 95fa4bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 16 additions & 0 deletions agent/qrexec-agent-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,23 @@ static int handle_new_process_common(int type, int connect_domain, int connect_p
case MSG_EXEC_CMDLINE:
buffer_init(&stdin_buf);
if (execute_qubes_rpc_command(cmdline, &pid, &stdin_fd, &stdout_fd, &stderr_fd, !qrexec_is_fork_server, &stdin_buf) < 0) {
struct msg_header hdr = {
.type = MSG_DATA_STDOUT,
.len = 0,
};
fputs("failed to spawn process\n", stderr);
/* Send stdout+stderr EOF first, since the service is expected to send
* one before exit code in case of MSG_EXEC_CMDLINE. Ignore
* libvchan_send error if any, as we're going to terminate soon
* anyway.
*/
libvchan_send(data_vchan, &hdr, sizeof(hdr));
hdr.type = MSG_DATA_STDERR;
libvchan_send(data_vchan, &hdr, sizeof(hdr));
exit_code = 127;
send_exit_code(data_vchan, exit_code);
libvchan_close(data_vchan);
return exit_code;
}
fprintf(stderr, "executed %s pid %d\n", cmdline, pid);
is_service = true;
Expand Down
1 change: 0 additions & 1 deletion qrexec/tests/socket/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ def test_exec_service(self):
(qrexec.MSG_DATA_EXIT_CODE, b'\0\0\0\0')
])

@pytest.mark.xfail
def test_exec_service_fail(self):
target = self.execute_qubesrpc('qubes.Service+arg', 'domX')
target.send_message(qrexec.MSG_DATA_STDIN, b'')
Expand Down

0 comments on commit 95fa4bb

Please sign in to comment.