@@ -534,16 +534,16 @@ static void release_vchan_port(int port, int expected_remote_id)
534
534
535
535
static int handle_cmdline_body_from_client (int fd , struct msg_header * hdr )
536
536
{
537
- struct exec_params params ;
537
+ struct exec_params * params = NULL ;
538
538
uint32_t len ;
539
- char * buf = NULL ;
539
+ char * buf ;
540
540
int use_default_user = 0 ;
541
541
int i ;
542
542
543
- if (hdr -> len <= sizeof (params )) {
543
+ if (hdr -> len <= sizeof (* params )) {
544
544
LOG (ERROR , "Too-short packet received from client %d: "
545
545
"type %" PRIu32 ", len %" PRIu32 "(min %zu)" ,
546
- fd , hdr -> type , hdr -> len , sizeof (params ) + 1 );
546
+ fd , hdr -> type , hdr -> len , sizeof (* params ) + 1 );
547
547
goto terminate ;
548
548
}
549
549
if (hdr -> len > MAX_QREXEC_CMD_LEN ) {
@@ -552,20 +552,18 @@ static int handle_cmdline_body_from_client(int fd, struct msg_header *hdr)
552
552
fd , hdr -> type , hdr -> len , MAX_QREXEC_CMD_LEN );
553
553
goto terminate ;
554
554
}
555
- len = hdr -> len - sizeof (params );
555
+ len = hdr -> len - sizeof (* params );
556
556
557
- buf = malloc (len );
558
- if (buf == NULL ) {
557
+ params = malloc (hdr -> len );
558
+ if (params == NULL ) {
559
559
PERROR ("malloc" );
560
560
goto terminate ;
561
561
}
562
562
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 )) {
567
564
goto terminate ;
568
565
}
566
+ buf = params -> cmdline ;
569
567
570
568
if (buf [len - 1 ] != '\0' ) {
571
569
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)
592
590
policy_pending [i ].response_sent = RESPONSE_ALLOW ;
593
591
}
594
592
595
- if (!params . connect_port ) {
593
+ if (!params -> connect_port ) {
596
594
struct exec_params client_params ;
597
595
/* 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 ) {
600
598
LOG (ERROR , "Failed to allocate new vchan port, too many clients?" );
601
599
goto terminate ;
602
600
}
603
601
/* 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 ;
606
604
client_params .connect_domain = remote_domain_id ;
607
605
hdr -> len = sizeof (client_params );
608
606
if (!write_all (fd , hdr , sizeof (* hdr )) ||
609
607
!write_all (fd , & client_params , sizeof (client_params ))) {
610
608
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 );
613
611
return 0 ;
614
612
}
615
613
/* restore original len value */
616
- hdr -> len = len + sizeof (params );
614
+ hdr -> len = len + sizeof (* params );
617
615
} 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 );
621
619
goto terminate ;
622
620
}
623
621
}
@@ -629,24 +627,25 @@ static int handle_cmdline_body_from_client(int fd, struct msg_header *hdr)
629
627
}
630
628
if (libvchan_send (vchan , hdr , sizeof (* hdr )) != sizeof (* hdr ))
631
629
handle_vchan_error ("send" );
632
- if (libvchan_send (vchan , & params , sizeof (params )) != sizeof (params ))
633
- handle_vchan_error ("send params" );
634
630
if (use_default_user ) {
635
631
int send_len = strlen (default_user );
632
+ if (libvchan_send (vchan , params , sizeof (* params )) != sizeof (* params ))
633
+ handle_vchan_error ("send params" );
636
634
if (libvchan_send (vchan , default_user , send_len ) != send_len )
637
635
handle_vchan_error ("send default_user" );
638
636
send_len = len - default_user_keyword_len_without_colon ;
639
637
if (libvchan_send (vchan , buf + default_user_keyword_len_without_colon ,
640
638
send_len ) != send_len )
641
639
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 )
644
642
handle_vchan_error ("send buf" );
645
- free (buf );
643
+ }
644
+ free (params );
646
645
return 1 ;
647
646
terminate :
648
647
terminate_client (fd );
649
- free (buf );
648
+ free (params );
650
649
return 0 ;
651
650
}
652
651
0 commit comments