From f4af20ae22ff25a117bcbdb2c684d13a04e7dd16 Mon Sep 17 00:00:00 2001 From: Virtually Nick Date: Sat, 1 Jun 2024 10:15:09 -0400 Subject: [PATCH] GUACAMOLE-1196: Use message lock where other RFB messages are sent. --- src/protocols/vnc/display.c | 6 +++++- src/protocols/vnc/vnc.c | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/protocols/vnc/display.c b/src/protocols/vnc/display.c index b64dfff6..ca7515e0 100644 --- a/src/protocols/vnc/display.c +++ b/src/protocols/vnc/display.c @@ -259,13 +259,17 @@ void guac_vnc_display_set_size(rfbClient* client, int width, int height) { /* Fit height within bounds, adjusting width to maintain aspect ratio */ guac_common_display_fit(&height, &width); - /* Send the display size update. */ + /* Acquire the lock for sending messages to server. */ pthread_mutex_lock(&(vnc_client->message_lock)); + + /* Send the display size update. */ guac_client_log(gc, GUAC_LOG_TRACE, "Setting VNC display size."); if (guac_vnc_send_desktop_size(client, width, height)) guac_client_log(gc, GUAC_LOG_TRACE, "Successfully sent desktop size message."); else guac_client_log(gc, GUAC_LOG_TRACE, "Failed to send desktop size message."); + + /* Release the lock. */ pthread_mutex_unlock(&(vnc_client->message_lock)); } diff --git a/src/protocols/vnc/vnc.c b/src/protocols/vnc/vnc.c index ec2c505d..829a474b 100644 --- a/src/protocols/vnc/vnc.c +++ b/src/protocols/vnc/vnc.c @@ -456,11 +456,17 @@ void* guac_vnc_client_thread(void* data) { msg.status = 1; msg.pad = 0; + /* Acquire lock for writing to server. */ + pthread_mutex_lock(&(vnc_client->message_lock)); + if (WriteToRFBServer(rfb_client, (char*)&msg, sz_rfbSetServerInputMsg)) guac_client_log(client, GUAC_LOG_DEBUG, "Successfully sent request to disable server input."); else guac_client_log(client, GUAC_LOG_WARNING, "Failed to send request to disable server input."); + + /* Release lock. */ + pthread_mutex_unlock(&(vnc_client->message_lock)); } /* Set remaining client data */