From 91485ba75d5a598eda5a041505c7c65648297e32 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 23 Jul 2024 17:28:03 +0200 Subject: Fix kms capture getting stuck if more than 1 fd per plane --- kms/client/kms_client.c | 2 +- kms/server/kms_server.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/kms/client/kms_client.c b/kms/client/kms_client.c index 966fa5e..d3e68dd 100644 --- a/kms/client/kms_client.c +++ b/kms/client/kms_client.c @@ -88,7 +88,7 @@ static int recv_msg_from_server(int server_pid, int server_fd, gsr_kms_response response_message.msg_iov = &iov; response_message.msg_iovlen = 1; - char cmsgbuf[CMSG_SPACE(sizeof(int) * GSR_KMS_MAX_ITEMS)]; + char cmsgbuf[CMSG_SPACE(sizeof(int) * GSR_KMS_MAX_ITEMS * GSR_KMS_MAX_DMA_BUFS)]; memset(cmsgbuf, 0, sizeof(cmsgbuf)); response_message.msg_control = cmsgbuf; response_message.msg_controllen = sizeof(cmsgbuf); diff --git a/kms/server/kms_server.c b/kms/server/kms_server.c index 2fdbd14..09c1f03 100644 --- a/kms/server/kms_server.c +++ b/kms/server/kms_server.c @@ -54,17 +54,18 @@ static int send_msg_to_client(int client_fd, gsr_kms_response *response) { response_message.msg_iov = &iov; response_message.msg_iovlen = 1; - char cmsgbuf[CMSG_SPACE(sizeof(int) * max_int(1, response->num_items))]; + const int num_fds = count_num_fds(response); + char cmsgbuf[CMSG_SPACE(sizeof(int) * max_int(1, num_fds))]; memset(cmsgbuf, 0, sizeof(cmsgbuf)); - if(response->num_items > 0) { + if(num_fds > 0) { response_message.msg_control = cmsgbuf; response_message.msg_controllen = sizeof(cmsgbuf); struct cmsghdr *cmsg = CMSG_FIRSTHDR(&response_message); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; - cmsg->cmsg_len = CMSG_LEN(sizeof(int) * count_num_fds(response)); + cmsg->cmsg_len = CMSG_LEN(sizeof(int) * num_fds); int *fds = (int*)CMSG_DATA(cmsg); int fd_index = 0; -- cgit v1.2.3