Skip to content

Commit 3313110

Browse files
committed
qrexec-daemon: Take advantage of flexible array members
No functional change intended.
1 parent e33f334 commit 3313110

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

daemon/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ override QUBES_CFLAGS:=-I../libqrexec -g -O2 -Wall -Wextra -Werror -fPIC \
55
-D_FORTIFY_SOURCE=2 -fstack-protector-strong -std=gnu11 -D_POSIX_C_SOURCE=200809L \
66
-D_GNU_SOURCE $(CFLAGS) \
77
-Wstrict-prototypes -Wold-style-definition -Wmissing-declarations \
8-
-fvisibility=hidden
8+
-fvisibility=hidden -fno-strict-aliasing
99
override LDFLAGS += -pie -Wl,-z,relro,-z,now -L../libqrexec
1010
override LDLIBS += $(shell pkg-config --libs $(VCHAN_PKG)) -lqrexec-utils
1111

daemon/qrexec-daemon.c

+27-28
Original file line numberDiff line numberDiff line change
@@ -534,16 +534,16 @@ static void release_vchan_port(int port, int expected_remote_id)
534534

535535
static int handle_cmdline_body_from_client(int fd, struct msg_header *hdr)
536536
{
537-
struct exec_params params;
537+
struct exec_params *params = NULL;
538538
uint32_t len;
539-
char *buf = NULL;
539+
char *buf;
540540
int use_default_user = 0;
541541
int i;
542542

543-
if (hdr->len <= sizeof(params)) {
543+
if (hdr->len <= sizeof(*params)) {
544544
LOG(ERROR, "Too-short packet received from client %d: "
545545
"type %" PRIu32 ", len %" PRIu32 "(min %zu)",
546-
fd, hdr->type, hdr->len, sizeof(params) + 1);
546+
fd, hdr->type, hdr->len, sizeof(*params) + 1);
547547
goto terminate;
548548
}
549549
if (hdr->len > MAX_QREXEC_CMD_LEN) {
@@ -552,20 +552,18 @@ static int handle_cmdline_body_from_client(int fd, struct msg_header *hdr)
552552
fd, hdr->type, hdr->len, MAX_QREXEC_CMD_LEN);
553553
goto terminate;
554554
}
555-
len = hdr->len - sizeof(params);
555+
len = hdr->len - sizeof(*params);
556556

557-
buf = malloc(len);
558-
if (buf == NULL) {
557+
params = malloc(hdr->len);
558+
if (params == NULL) {
559559
PERROR("malloc");
560560
goto terminate;
561561
}
562562

563-
if (!read_all(fd, &params, sizeof(params))) {
564-
goto terminate;
565-
}
566-
if (!read_all(fd, buf, len)) {
563+
if (!read_all(fd, params, hdr->len)) {
567564
goto terminate;
568565
}
566+
buf = params->cmdline;
569567

570568
if (buf[len - 1] != '\0') {
571569
LOG(ERROR, "Client sent buffer of length %" PRIu32 " that is not "
@@ -592,32 +590,32 @@ static int handle_cmdline_body_from_client(int fd, struct msg_header *hdr)
592590
policy_pending[i].response_sent = RESPONSE_ALLOW;
593591
}
594592

595-
if (!params.connect_port) {
593+
if (!params->connect_port) {
596594
struct exec_params client_params;
597595
/* allocate port and send it to the client */
598-
params.connect_port = allocate_vchan_port(params.connect_domain);
599-
if (params.connect_port <= 0) {
596+
params->connect_port = allocate_vchan_port(params->connect_domain);
597+
if (params->connect_port <= 0) {
600598
LOG(ERROR, "Failed to allocate new vchan port, too many clients?");
601599
goto terminate;
602600
}
603601
/* notify the client when this connection got terminated */
604-
vchan_port_notify_client[params.connect_port-VCHAN_BASE_DATA_PORT] = fd;
605-
client_params.connect_port = params.connect_port;
602+
vchan_port_notify_client[params->connect_port-VCHAN_BASE_DATA_PORT] = fd;
603+
client_params.connect_port = params->connect_port;
606604
client_params.connect_domain = remote_domain_id;
607605
hdr->len = sizeof(client_params);
608606
if (!write_all(fd, hdr, sizeof(*hdr)) ||
609607
!write_all(fd, &client_params, sizeof(client_params))) {
610608
terminate_client(fd);
611-
release_vchan_port(params.connect_port, params.connect_domain);
612-
free(buf);
609+
release_vchan_port(params->connect_port, params->connect_domain);
610+
free(params);
613611
return 0;
614612
}
615613
/* restore original len value */
616-
hdr->len = len+sizeof(params);
614+
hdr->len = len+sizeof(*params);
617615
} else {
618-
if (!((params.connect_port >= VCHAN_BASE_DATA_PORT) &&
619-
(params.connect_port < VCHAN_BASE_DATA_PORT+MAX_CLIENTS))) {
620-
LOG(ERROR, "Invalid connect port %" PRIu32, params.connect_port);
616+
if (!((params->connect_port >= VCHAN_BASE_DATA_PORT) &&
617+
(params->connect_port < VCHAN_BASE_DATA_PORT+MAX_CLIENTS))) {
618+
LOG(ERROR, "Invalid connect port %" PRIu32, params->connect_port);
621619
goto terminate;
622620
}
623621
}
@@ -629,24 +627,25 @@ static int handle_cmdline_body_from_client(int fd, struct msg_header *hdr)
629627
}
630628
if (libvchan_send(vchan, hdr, sizeof(*hdr)) != sizeof(*hdr))
631629
handle_vchan_error("send");
632-
if (libvchan_send(vchan, &params, sizeof(params)) != sizeof(params))
633-
handle_vchan_error("send params");
634630
if (use_default_user) {
635631
int send_len = strlen(default_user);
632+
if (libvchan_send(vchan, params, sizeof(*params)) != sizeof(*params))
633+
handle_vchan_error("send params");
636634
if (libvchan_send(vchan, default_user, send_len) != send_len)
637635
handle_vchan_error("send default_user");
638636
send_len = len-default_user_keyword_len_without_colon;
639637
if (libvchan_send(vchan, buf+default_user_keyword_len_without_colon,
640638
send_len) != send_len)
641639
handle_vchan_error("send buf");
642-
} else
643-
if (libvchan_send(vchan, buf, len) < (int)len)
640+
} else {
641+
if (libvchan_send(vchan, params, hdr->len) != (int)hdr->len)
644642
handle_vchan_error("send buf");
645-
free(buf);
643+
}
644+
free(params);
646645
return 1;
647646
terminate:
648647
terminate_client(fd);
649-
free(buf);
648+
free(params);
650649
return 0;
651650
}
652651

qrexec/tests/socket/daemon.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def test_client_exec(self):
377377
def client_exec(
378378
self,
379379
domain: int,
380-
cmd: str = "user:echo Hello world",
380+
cmd: str = "DEFAULT:echo Hello world",
381381
message_type: int = qrexec.MSG_JUST_EXEC,
382382
):
383383
client = self.connect_client()

0 commit comments

Comments
 (0)