@@ -57,10 +57,8 @@ struct connection_info {
57
57
* finish */
58
58
struct waiting_request {
59
59
int type ;
60
- int connect_domain ;
61
- int connect_port ;
62
60
int padding ;
63
- char * cmdline ;
61
+ struct exec_params * params ;
64
62
struct qrexec_parsed_command * cmd ;
65
63
};
66
64
@@ -82,9 +80,9 @@ static int meminfo_write_started = 0;
82
80
static const char * agent_trigger_path = QREXEC_AGENT_TRIGGER_PATH ;
83
81
static const char * fork_server_path = QREXEC_FORK_SERVER_SOCKET ;
84
82
85
- static void handle_server_exec_request_do (int type , int connect_domain , int connect_port ,
83
+ static void handle_server_exec_request_do (int type ,
86
84
struct qrexec_parsed_command * cmd ,
87
- char * cmdline );
85
+ struct exec_params * params );
88
86
static void terminate_connection (uint32_t domain , uint32_t port );
89
87
90
88
const bool qrexec_is_fork_server = false;
@@ -427,7 +425,7 @@ static void wake_meminfo_writer(void)
427
425
}
428
426
429
427
static int try_fork_server (int type , int connect_domain , int connect_port ,
430
- char * cmdline , size_t cmdline_len , const char * username ) {
428
+ const char * cmdline , size_t cmdline_len , const char * username ) {
431
429
char * colon ;
432
430
char * fork_server_socket_path ;
433
431
int s = -1 ;
@@ -560,37 +558,31 @@ static bool wait_for_session_maybe(struct qrexec_parsed_command *cmd) {
560
558
/* hdr parameter is received from dom0, so it is trusted */
561
559
static void handle_server_exec_request_init (struct msg_header * hdr )
562
560
{
563
- struct exec_params params ;
564
561
struct qrexec_parsed_command * cmd ;
565
- if (hdr -> len <= sizeof (params ))
566
- abort ();
567
- size_t buf_len = hdr -> len - sizeof (params );
568
- if (buf_len > INT_MAX )
569
- abort ();
570
- char * buf = malloc (buf_len );
571
- if (!buf )
572
- abort ();
573
-
574
- if (libvchan_recv (ctrl_vchan , & params , sizeof (params )) != sizeof (params ))
562
+ struct exec_params * params ;
563
+ if (hdr -> len <= sizeof (* params ) || hdr -> len > (uint32_t )INT_MAX )
564
+ handle_vchan_error ("buffer size validation" );
565
+ size_t buf_len = hdr -> len - sizeof (* params );
566
+ params = malloc (hdr -> len );
567
+ if (params == NULL )
568
+ handle_vchan_error ("buffer alloc" );
569
+ if (libvchan_recv (ctrl_vchan , params , hdr -> len ) != (int )hdr -> len )
575
570
handle_vchan_error ("read exec params" );
576
- if (libvchan_recv (ctrl_vchan , buf , (int )buf_len ) != (int )buf_len )
577
- handle_vchan_error ("read exec cmd" );
578
-
579
- buf [buf_len - 1 ] = 0 ;
571
+ params -> cmdline [buf_len - 1 ] = 0 ;
580
572
581
573
if (hdr -> type == MSG_SERVICE_CONNECT ) {
582
574
cmd = NULL ;
583
575
} else {
584
- cmd = parse_qubes_rpc_command (buf , true);
576
+ cmd = parse_qubes_rpc_command (params -> cmdline , true);
585
577
if (cmd == NULL ) {
586
- LOG (ERROR , "Could not parse command line: %s" , buf );
578
+ LOG (ERROR , "Could not parse command line: %s" , params -> cmdline );
587
579
goto doit ;
588
580
}
589
581
590
582
/* load service config only for service requests */
591
583
if (cmd -> service_descriptor ) {
592
584
if (load_service_config_v2 (cmd ) < 0 ) {
593
- LOG (ERROR , "Could not load config for command %s" , buf );
585
+ LOG (ERROR , "Could not load config for command %s" , params -> cmdline );
594
586
destroy_qrexec_parsed_command (cmd );
595
587
cmd = NULL ;
596
588
goto doit ;
@@ -601,16 +593,14 @@ static void handle_server_exec_request_init(struct msg_header *hdr)
601
593
/* waiting for session, postpone actual call */
602
594
int slot_index ;
603
595
for (slot_index = 0 ; slot_index < MAX_FDS ; slot_index ++ )
604
- if (!requests_waiting_for_session [slot_index ].cmdline )
596
+ if (!requests_waiting_for_session [slot_index ].params )
605
597
break ;
606
598
if (slot_index == MAX_FDS ) {
607
599
/* no free slots */
608
600
LOG (WARNING , "No free slots for waiting for GUI session, continuing!" );
609
601
} else {
610
602
requests_waiting_for_session [slot_index ].type = hdr -> type ;
611
- requests_waiting_for_session [slot_index ].connect_domain = params .connect_domain ;
612
- requests_waiting_for_session [slot_index ].connect_port = params .connect_port ;
613
- requests_waiting_for_session [slot_index ].cmdline = buf ;
603
+ requests_waiting_for_session [slot_index ].params = params ;
614
604
requests_waiting_for_session [slot_index ].cmd = cmd ;
615
605
/* nothing to do now, when we get GUI session, we'll continue */
616
606
return ;
@@ -620,23 +610,18 @@ static void handle_server_exec_request_init(struct msg_header *hdr)
620
610
}
621
611
622
612
doit :
623
- handle_server_exec_request_do (hdr -> type , params . connect_domain , params . connect_port , cmd , buf );
613
+ handle_server_exec_request_do (hdr -> type , cmd , params );
624
614
destroy_qrexec_parsed_command (cmd );
625
- free (buf );
615
+ free (params );
626
616
}
627
617
628
618
static void handle_server_exec_request_do (int type ,
629
- int connect_domain ,
630
- int connect_port ,
631
619
struct qrexec_parsed_command * cmd ,
632
- char * cmdline ) {
620
+ struct exec_params * params ) {
633
621
int client_fd ;
634
622
pid_t child_agent ;
623
+ const char * cmdline = params -> cmdline ;
635
624
size_t cmdline_len = strlen (cmdline ) + 1 ; // size of cmdline, including \0 at the end
636
- struct exec_params params = {
637
- .connect_domain = connect_domain ,
638
- .connect_port = connect_port ,
639
- };
640
625
641
626
if (type == MSG_SERVICE_CONNECT ) {
642
627
if (sscanf (cmdline , "SOCKET%d" , & client_fd ) != 1 )
@@ -646,7 +631,7 @@ static void handle_server_exec_request_do(int type,
646
631
* qrexec-client-vm process; but this data comes from qrexec-daemon
647
632
* (which sends back what it got from us earlier), so it isn't critical.
648
633
*/
649
- if (write (client_fd , & params , sizeof (params )) < 0 ) {
634
+ if (write (client_fd , params , sizeof (* params )) < 0 ) {
650
635
/* Do not start polling invalid FD */
651
636
if (errno == EBADF )
652
637
goto bad_ident ;
@@ -659,29 +644,29 @@ static void handle_server_exec_request_do(int type,
659
644
* (close socket, send MSG_CONNECTION_TERMINATED) when qrexec-client-vm
660
645
* will close the socket (terminate itself). */
661
646
register_vchan_connection (-1 , client_fd ,
662
- params . connect_domain , params . connect_port );
647
+ params -> connect_domain , params -> connect_port );
663
648
return ;
664
649
}
665
650
666
651
if (cmd != NULL && !cmd -> nogui ) {
667
652
/* try fork server */
668
653
int child_socket = try_fork_server (type ,
669
- params . connect_domain , params . connect_port ,
654
+ params -> connect_domain , params -> connect_port ,
670
655
cmdline , cmdline_len , cmd -> username );
671
656
if (child_socket >= 0 ) {
672
657
register_vchan_connection (-1 , child_socket ,
673
- params . connect_domain , params . connect_port );
658
+ params -> connect_domain , params -> connect_port );
674
659
return ;
675
660
}
676
661
}
677
662
678
663
/* No fork server case */
679
664
child_agent = handle_new_process (type ,
680
- params . connect_domain , params . connect_port ,
665
+ params -> connect_domain , params -> connect_port ,
681
666
cmd );
682
667
683
668
register_vchan_connection (child_agent , -1 ,
684
- params . connect_domain , params . connect_port );
669
+ params -> connect_domain , params -> connect_port );
685
670
return ;
686
671
bad_ident :
687
672
LOG (ERROR , "Got MSG_SERVICE_CONNECT from qrexec-daemon with invalid ident (%s), ignoring" ,
@@ -788,18 +773,16 @@ static void reap_children(void)
788
773
while ((pid = waitpid (-1 , & status , WNOHANG )) > 0 ) {
789
774
if (pid == wait_for_session_pid ) {
790
775
for (id = 0 ; id < MAX_FDS ; id ++ ) {
791
- if (!requests_waiting_for_session [id ].cmdline )
776
+ if (!requests_waiting_for_session [id ].params )
792
777
continue ;
793
778
handle_server_exec_request_do (
794
779
requests_waiting_for_session [id ].type ,
795
- requests_waiting_for_session [id ].connect_domain ,
796
- requests_waiting_for_session [id ].connect_port ,
797
780
requests_waiting_for_session [id ].cmd ,
798
- requests_waiting_for_session [id ].cmdline );
781
+ requests_waiting_for_session [id ].params );
799
782
destroy_qrexec_parsed_command (requests_waiting_for_session [id ].cmd );
800
783
requests_waiting_for_session [id ].cmd = NULL ;
801
- free (requests_waiting_for_session [id ].cmdline );
802
- requests_waiting_for_session [id ].cmdline = NULL ;
784
+ free (requests_waiting_for_session [id ].params );
785
+ requests_waiting_for_session [id ].params = NULL ;
803
786
}
804
787
wait_for_session_pid = -1 ;
805
788
continue ;
0 commit comments