Skip to content

Commit

Permalink
Remove the connect_existing variable
Browse files Browse the repository at this point in the history
gcc was (incorrectly) warning that request_id could be used
uninitialized.  Initialize it to NULL and use it being non-NULL instead
of connect_existing.

(cherry picked from commit 2b569b1)
  • Loading branch information
DemiMarie authored and marmarek committed May 12, 2023
1 parent 30e4629 commit e63e87f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions daemon/qrexec-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ int main(int argc, char **argv)
int s;
int just_exec = 0;
int wait_connection_end = 0;
int connect_existing = 0;
char *local_cmdline = NULL;
char *remote_cmdline = NULL;
char *request_id = NULL;
Expand Down Expand Up @@ -544,7 +543,6 @@ int main(int argc, char **argv)
break;
case 'c':
parse_connect(optarg, &request_id, &src_domain_name, &src_domain_id);
connect_existing = 1;
is_service = 1;
break;
case 't':
Expand Down Expand Up @@ -575,13 +573,13 @@ int main(int argc, char **argv)

register_exec_func(&do_exec);

if (just_exec + connect_existing + (local_cmdline != 0) > 1) {
if (just_exec + (request_id != NULL) + (local_cmdline != 0) > 1) {
fprintf(stderr, "ERROR: only one of -e, -l, -c can be specified\n");
usage(argv[0]);
}

if (strcmp(domname, "dom0") == 0 || strcmp(domname, "@adminvm") == 0) {
if (connect_existing) {
if (request_id != NULL) {
msg_type = MSG_SERVICE_CONNECT;
strncpy(svc_params.ident, request_id, sizeof(svc_params.ident) - 1);
svc_params.ident[sizeof(svc_params.ident) - 1] = '\0';
Expand All @@ -598,16 +596,16 @@ int main(int argc, char **argv)
negotiate_connection_params(s,
0, /* dom0 */
msg_type,
connect_existing ? (void*)&svc_params : (void*)remote_cmdline,
connect_existing ? sizeof(svc_params) : compute_service_length(remote_cmdline, argv[0]),
request_id ? (void*)&svc_params : (void*)remote_cmdline,
request_id ? sizeof(svc_params) : compute_service_length(remote_cmdline, argv[0]),
&data_domain,
&data_port);

struct buffer stdin_buffer;
buffer_init(&stdin_buffer);
wait_for_session_maybe(remote_cmdline);
prepare_ret = prepare_local_fds(remote_cmdline, &stdin_buffer);
if (connect_existing) {
if (request_id) {
void (*old_handler)(int);

/* libvchan_client_init is blocking and does not support connection
Expand All @@ -626,7 +624,7 @@ int main(int argc, char **argv)
LOG(ERROR, "Failed to open data vchan connection");
exit(1);
}
data_protocol_version = handle_agent_handshake(data_vchan, connect_existing);
data_protocol_version = handle_agent_handshake(data_vchan, request_id != NULL);
if (data_protocol_version < 0)
exit(1);
if (prepare_ret < 0)
Expand All @@ -642,7 +640,7 @@ int main(int argc, char **argv)
compute_service_length(remote_cmdline, argv[0]),
&data_domain,
&data_port);
if (wait_connection_end && connect_existing)
if (wait_connection_end && request_id)
/* save socket fd, 's' will be reused for the other qrexec-daemon
* connection */
wait_connection_end = s;
Expand All @@ -652,7 +650,7 @@ int main(int argc, char **argv)
struct buffer stdin_buffer;
buffer_init(&stdin_buffer);
prepare_ret = prepare_local_fds(local_cmdline, &stdin_buffer);
if (connect_existing) {
if (request_id) {
s = connect_unix_socket(src_domain_name);
send_service_connect(s, request_id, data_domain, data_port);
close(s);
Expand Down

0 comments on commit e63e87f

Please sign in to comment.