From 236368150f800d7f8c9a8b9c972cefe25adcafd4 Mon Sep 17 00:00:00 2001 From: Virtually Nick Date: Thu, 28 Dec 2023 16:04:18 -0500 Subject: [PATCH] GUACAMOLE-1140: Fix RDP pipe svc race condition with lock and null check. --- src/protocols/rdp/channels/pipe-svc.c | 18 ++++++++++-------- src/protocols/rdp/client.c | 4 ++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/protocols/rdp/channels/pipe-svc.c b/src/protocols/rdp/channels/pipe-svc.c index 9029c207a..a8bcfd64f 100644 --- a/src/protocols/rdp/channels/pipe-svc.c +++ b/src/protocols/rdp/channels/pipe-svc.c @@ -48,16 +48,18 @@ void guac_rdp_pipe_svc_send_pipes( guac_rdp_client* rdp_client = (guac_rdp_client*) client->data; - guac_common_list_lock(rdp_client->available_svc); + if (rdp_client->available_svc != NULL) { + guac_common_list_lock(rdp_client->available_svc); + + /* Send pipe for each allocated SVC's output stream */ + guac_common_list_element* current = rdp_client->available_svc->head; + while (current != NULL) { + guac_rdp_pipe_svc_send_pipe(socket, (guac_rdp_pipe_svc*) current->data); + current = current->next; + } - /* Send pipe for each allocated SVC's output stream */ - guac_common_list_element* current = rdp_client->available_svc->head; - while (current != NULL) { - guac_rdp_pipe_svc_send_pipe(socket, (guac_rdp_pipe_svc*) current->data); - current = current->next; + guac_common_list_unlock(rdp_client->available_svc); } - - guac_common_list_unlock(rdp_client->available_svc); } void guac_rdp_pipe_svc_add(guac_client* client, guac_rdp_pipe_svc* pipe_svc) { diff --git a/src/protocols/rdp/client.c b/src/protocols/rdp/client.c index 8f8c4f689..e98a0f3a5 100644 --- a/src/protocols/rdp/client.c +++ b/src/protocols/rdp/client.c @@ -117,6 +117,8 @@ static int guac_rdp_join_pending_handler(guac_client* client) { guac_rdp_client* rdp_client = (guac_rdp_client*) client->data; guac_socket* broadcast_socket = client->pending_socket; + pthread_rwlock_rdlock(&(rdp_client->lock)); + /* Synchronize any audio stream for each pending user */ if (rdp_client->audio) guac_client_foreach_pending_user( @@ -131,6 +133,8 @@ static int guac_rdp_join_pending_handler(guac_client* client) { guac_socket_flush(broadcast_socket); } + pthread_rwlock_unlock(&(rdp_client->lock)); + return 0; }