Skip to content

Commit 5a62613

Browse files
committed
qrexec-client: remove unreachable code
All of this code could only be reached if request_id is NULL when the target domain is dom0, but in that case the code already calls exit(1). Also refactor the code slightly to make this more obvious.
1 parent 756bd39 commit 5a62613

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

daemon/qrexec-client.c

+16-23
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,13 @@ int main(int argc, char **argv)
629629
}
630630

631631
if (strcmp(domname, "dom0") == 0 || strcmp(domname, "@adminvm") == 0) {
632-
if (request_id != NULL) {
633-
msg_type = MSG_SERVICE_CONNECT;
634-
strncpy(svc_params.ident, request_id, sizeof(svc_params.ident) - 1);
635-
svc_params.ident[sizeof(svc_params.ident) - 1] = '\0';
636-
} else {
632+
if (request_id == NULL) {
637633
fprintf(stderr, "ERROR: when target domain is 'dom0', -c must be specified\n");
638634
usage(argv[0]);
639635
}
636+
msg_type = MSG_SERVICE_CONNECT;
637+
strncpy(svc_params.ident, request_id, sizeof(svc_params.ident) - 1);
638+
svc_params.ident[sizeof(svc_params.ident) - 1] = '\0';
640639
if (src_domain_name == NULL) {
641640
LOG(ERROR, "internal error: src_domain_name should not be NULL here");
642641
abort();
@@ -646,8 +645,8 @@ int main(int argc, char **argv)
646645
negotiate_connection_params(s,
647646
0, /* dom0 */
648647
msg_type,
649-
request_id ? (void*)&svc_params : (void*)remote_cmdline,
650-
request_id ? sizeof(svc_params) : compute_service_length(remote_cmdline, argv[0]),
648+
(void*)&svc_params,
649+
sizeof(svc_params),
651650
&data_domain,
652651
&data_port);
653652

@@ -659,26 +658,20 @@ int main(int argc, char **argv)
659658
} else {
660659
prepare_ret = prepare_local_fds(remote_cmdline, &stdin_buffer);
661660
}
662-
if (request_id) {
663-
void (*old_handler)(int);
664-
665-
/* libvchan_client_init is blocking and does not support connection
666-
* timeout, so use alarm(2) for that... */
667-
old_handler = signal(SIGALRM, sigalrm_handler);
668-
alarm(connection_timeout);
669-
data_vchan = libvchan_client_init(data_domain, data_port);
670-
alarm(0);
671-
signal(SIGALRM, old_handler);
672-
} else {
673-
data_vchan = libvchan_server_init(data_domain, data_port,
674-
VCHAN_BUFFER_SIZE, VCHAN_BUFFER_SIZE);
675-
wait_for_vchan_client_with_timeout(data_vchan, connection_timeout);
676-
}
661+
void (*old_handler)(int);
662+
663+
/* libvchan_client_init is blocking and does not support connection
664+
* timeout, so use alarm(2) for that... */
665+
old_handler = signal(SIGALRM, sigalrm_handler);
666+
alarm(connection_timeout);
667+
data_vchan = libvchan_client_init(data_domain, data_port);
668+
alarm(0);
669+
signal(SIGALRM, old_handler);
677670
if (!data_vchan || !libvchan_is_open(data_vchan)) {
678671
LOG(ERROR, "Failed to open data vchan connection");
679672
exit(1);
680673
}
681-
data_protocol_version = handle_agent_handshake(data_vchan, request_id != NULL);
674+
data_protocol_version = handle_agent_handshake(data_vchan, true);
682675
if (data_protocol_version < 0)
683676
exit(1);
684677
if (prepare_ret < 0)

0 commit comments

Comments
 (0)